From 4dfb988a3f7223f9d1dfe2bd5a9ff9edb6520a89 Mon Sep 17 00:00:00 2001 From: Simon H <5968653+dummdidumm@users.noreply.github.com> Date: Fri, 27 Sep 2024 22:56:44 +0200 Subject: [PATCH] fix: relax component constructor type (#2524) Since , we're no longer adding the `[evt: string]: CustomEvent` index signature to components in runes mode not using `createEventDispatcher`. This revealed a type bug in our `ATypedSvelteComponent` type. It was to restricting, because TypeScript will resolve the empty event object to a handler with callback type `never`, which then means the `__sveltets_2_ensureComponent` generic no longer picks the right type, resulting in generics not being resolved properly. Fix this by relaxing the constraints. Fixes #2523 --- .../generics-runes.v5/ValueComponent.svelte | 6 ++++++ .../generics-runes.v5/expectedv2.json | 19 +++++++++++++++++++ .../fixtures/generics-runes.v5/input.svelte | 11 +++++++++++ packages/svelte2tsx/svelte-shims-v4.d.ts | 2 +- 4 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 packages/language-server/test/plugins/typescript/features/diagnostics/fixtures/generics-runes.v5/ValueComponent.svelte create mode 100644 packages/language-server/test/plugins/typescript/features/diagnostics/fixtures/generics-runes.v5/expectedv2.json create mode 100644 packages/language-server/test/plugins/typescript/features/diagnostics/fixtures/generics-runes.v5/input.svelte diff --git a/packages/language-server/test/plugins/typescript/features/diagnostics/fixtures/generics-runes.v5/ValueComponent.svelte b/packages/language-server/test/plugins/typescript/features/diagnostics/fixtures/generics-runes.v5/ValueComponent.svelte new file mode 100644 index 000000000..7d2dd5ebc --- /dev/null +++ b/packages/language-server/test/plugins/typescript/features/diagnostics/fixtures/generics-runes.v5/ValueComponent.svelte @@ -0,0 +1,6 @@ + + +{value} +{defaultValue} \ No newline at end of file diff --git a/packages/language-server/test/plugins/typescript/features/diagnostics/fixtures/generics-runes.v5/expectedv2.json b/packages/language-server/test/plugins/typescript/features/diagnostics/fixtures/generics-runes.v5/expectedv2.json new file mode 100644 index 000000000..90f0fd771 --- /dev/null +++ b/packages/language-server/test/plugins/typescript/features/diagnostics/fixtures/generics-runes.v5/expectedv2.json @@ -0,0 +1,19 @@ +[ + { + "code": 2322, + "message": "Type 'number' is not assignable to type 'string'.", + "range": { + "end": { + "character": 36, + "line": 10 + }, + "start": { + "character": 24, + "line": 10 + } + }, + "severity": 1, + "source": "ts", + "tags": [] + } +] diff --git a/packages/language-server/test/plugins/typescript/features/diagnostics/fixtures/generics-runes.v5/input.svelte b/packages/language-server/test/plugins/typescript/features/diagnostics/fixtures/generics-runes.v5/input.svelte new file mode 100644 index 000000000..d2442ff89 --- /dev/null +++ b/packages/language-server/test/plugins/typescript/features/diagnostics/fixtures/generics-runes.v5/input.svelte @@ -0,0 +1,11 @@ + + + + + + + \ No newline at end of file diff --git a/packages/svelte2tsx/svelte-shims-v4.d.ts b/packages/svelte2tsx/svelte-shims-v4.d.ts index 71bfbac6d..2d36a539d 100644 --- a/packages/svelte2tsx/svelte-shims-v4.d.ts +++ b/packages/svelte2tsx/svelte-shims-v4.d.ts @@ -207,7 +207,7 @@ declare type ATypedSvelteComponent = { */ $$slot_def: any; - $on(event: string, handler: ((e: any) => any) | null | undefined): () => void; + $on(event: string, handler: any): () => void; } /** * Ambient type only used for intellisense, DO NOT USE IN YOUR PROJECT.