Skip to content

Commit

Permalink
chore: tests for #8872
Browse files Browse the repository at this point in the history
  • Loading branch information
dummdidumm committed Jun 29, 2023
1 parent 9086055 commit 1de2144
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
8 changes: 8 additions & 0 deletions packages/svelte/test/types/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,11 @@ invalidAttributes1;
// @ts-expect-error missing prop
const invalidAttributes2: Attributes = {};
invalidAttributes2;

function generic_action<T extends boolean>(_node: HTMLElement, param: T): ActionReturn<T> {
return {
update: (p) => p === param,
destroy: () => {}
};
}
generic_action;
21 changes: 21 additions & 0 deletions packages/svelte/test/types/create-event-dispatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,24 @@ dispatch('optional', undefined, { cancelable: true });
dispatch('optional', 'string');
// @ts-expect-error: wrong type of option
dispatch('optional', undefined, { cancelabled: true });

function generic_fn<T extends boolean>(t: T) {
const dispatch = createEventDispatcher<{
required: T;
optional: T | null;
}>();

dispatch('required', t);
dispatch('optional', t);
dispatch('optional', null);
dispatch('optional', undefined);
// @ts-expect-error: wrong type of optional detail
dispatch('optional', 'string');
// @ts-expect-error: wrong type of required detail
dispatch('required', 'string');
// @ts-expect-error: wrong type of optional detail
dispatch('optional', true);
// @ts-expect-error: wrong type of required detail
dispatch('required', true);
}
generic_fn;

0 comments on commit 1de2144

Please sign in to comment.