From 1de2144daee3dfec58169c41b9ece5148bd5bf88 Mon Sep 17 00:00:00 2001 From: Simon Holthausen Date: Thu, 29 Jun 2023 09:35:00 +0200 Subject: [PATCH] chore: tests for #8872 --- packages/svelte/test/types/actions.ts | 8 +++++++ .../test/types/create-event-dispatcher.ts | 21 +++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/packages/svelte/test/types/actions.ts b/packages/svelte/test/types/actions.ts index da4e660a1a..2e5444481a 100644 --- a/packages/svelte/test/types/actions.ts +++ b/packages/svelte/test/types/actions.ts @@ -124,3 +124,11 @@ invalidAttributes1; // @ts-expect-error missing prop const invalidAttributes2: Attributes = {}; invalidAttributes2; + +function generic_action(_node: HTMLElement, param: T): ActionReturn { + return { + update: (p) => p === param, + destroy: () => {} + }; +} +generic_action; diff --git a/packages/svelte/test/types/create-event-dispatcher.ts b/packages/svelte/test/types/create-event-dispatcher.ts index f85196930b..296550dbfa 100644 --- a/packages/svelte/test/types/create-event-dispatcher.ts +++ b/packages/svelte/test/types/create-event-dispatcher.ts @@ -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: 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;