From cc4a8678184da6e7f12694a9bd290749ca515078 Mon Sep 17 00:00:00 2001 From: "Lyu, Wei Da" Date: Mon, 7 Feb 2022 13:43:13 +0800 Subject: [PATCH] (fix) no error for component typedef with event --- .../fixtures/component-invalid/expected.json | 4 ++-- .../fixtures/component-invalid/expectedv2.json | 6 +++--- .../fixtures/component-invalid/input.svelte | 12 ++++++++++++ packages/svelte2tsx/svelte-shims.d.ts | 2 +- 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/packages/language-server/test/plugins/typescript/features/diagnostics/fixtures/component-invalid/expected.json b/packages/language-server/test/plugins/typescript/features/diagnostics/fixtures/component-invalid/expected.json index 4034fa6cb..d57488bab 100644 --- a/packages/language-server/test/plugins/typescript/features/diagnostics/fixtures/component-invalid/expected.json +++ b/packages/language-server/test/plugins/typescript/features/diagnostics/fixtures/component-invalid/expected.json @@ -1,8 +1,8 @@ [ { "range": { - "start": { "line": 13, "character": 1 }, - "end": { "line": 13, "character": 11 } + "start": { "line": 25, "character": 1 }, + "end": { "line": 25, "character": 11 } }, "severity": 1, "source": "ts", diff --git a/packages/language-server/test/plugins/typescript/features/diagnostics/fixtures/component-invalid/expectedv2.json b/packages/language-server/test/plugins/typescript/features/diagnostics/fixtures/component-invalid/expectedv2.json index 9f49e1b82..662c89dfb 100644 --- a/packages/language-server/test/plugins/typescript/features/diagnostics/fixtures/component-invalid/expectedv2.json +++ b/packages/language-server/test/plugins/typescript/features/diagnostics/fixtures/component-invalid/expectedv2.json @@ -1,12 +1,12 @@ [ { "range": { - "start": { "line": 13, "character": 1 }, - "end": { "line": 13, "character": 11 } + "start": { "line": 25, "character": 1 }, + "end": { "line": 25, "character": 11 } }, "severity": 1, "source": "ts", - "message": "Type definitions are missing for this Svelte Component. If you are using Svelte 3.31+, use SvelteComponentTyped to add a definition:\n import type { SvelteComponentTyped } from \"svelte\";\n class ComponentName extends SvelteComponentTyped<{propertyName: string;}> {}\n\nUnderlying error:\nArgument of type 'typeof DoesntWork' is not assignable to parameter of type 'new (args: { target: any; props?: any; }) => Svelte2TsxComponent'.\n Type 'DoesntWork' is missing the following properties from type 'Svelte2TsxComponent': $$prop_def, $$events_def, $$slot_def, $on, and 5 more.", + "message": "Type definitions are missing for this Svelte Component. If you are using Svelte 3.31+, use SvelteComponentTyped to add a definition:\n import type { SvelteComponentTyped } from \"svelte\";\n class ComponentName extends SvelteComponentTyped<{propertyName: string;}> {}\n\nUnderlying error:\nArgument of type 'typeof DoesntWork' is not assignable to parameter of type 'new (args: { target: any; props?: any; }) => Svelte2TsxComponent'.\n Type 'DoesntWork' is missing the following properties from type 'Svelte2TsxComponent': $$prop_def, $$events_def, $$slot_def, $on, and 5 more.", "code": 2345, "tags": [] } diff --git a/packages/language-server/test/plugins/typescript/features/diagnostics/fixtures/component-invalid/input.svelte b/packages/language-server/test/plugins/typescript/features/diagnostics/fixtures/component-invalid/input.svelte index 8fd5465da..d5e7d39a2 100644 --- a/packages/language-server/test/plugins/typescript/features/diagnostics/fixtures/component-invalid/input.svelte +++ b/packages/language-server/test/plugins/typescript/features/diagnostics/fixtures/component-invalid/input.svelte @@ -3,12 +3,24 @@ import Imported from './imported.svelte'; class Works extends SvelteComponentTyped {} + class Works2 extends SvelteComponentTyped< + { hi: string }, + { click: MouseEvent }, + { + default: { + foo: string; + }; + } + > {} class DoesntWork {} + console.log(e.movementX)} let:foo> + {foo.toLocaleLowerCase()} + diff --git a/packages/svelte2tsx/svelte-shims.d.ts b/packages/svelte2tsx/svelte-shims.d.ts index 1ef4fcf23..c9964892c 100644 --- a/packages/svelte2tsx/svelte-shims.d.ts +++ b/packages/svelte2tsx/svelte-shims.d.ts @@ -256,6 +256,6 @@ declare function __sveltets_2_ensureTransition(transitionCall: __sveltets_2_Svel declare function __sveltets_2_ensureType(type: AConstructorTypeOf, el: T): {}; declare function __sveltets_2_ensureType(type1: AConstructorTypeOf, type2: AConstructorTypeOf, el: T1 | T2): {}; -declare function __sveltets_2_ensureComponent Svelte2TsxComponent>(type: T): T extends never ? Svelte2TsxComponent : T; +declare function __sveltets_2_ensureComponent Svelte2TsxComponent>(type: T): T extends never ? Svelte2TsxComponent : T; declare function __sveltets_2_ensureArray>(array: T): T extends ArrayLike ? U[] : any[];