From cc8c8eeb5a4eb35cff77c090c4da44198805e6cd Mon Sep 17 00:00:00 2001 From: Theodor Steiner Date: Mon, 11 Nov 2024 12:54:40 +0900 Subject: [PATCH 1/7] fix: export private component type (#14256) --- packages/svelte/src/ambient.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/svelte/src/ambient.d.ts b/packages/svelte/src/ambient.d.ts index 8a20a884ff1d..399a2dc60087 100644 --- a/packages/svelte/src/ambient.d.ts +++ b/packages/svelte/src/ambient.d.ts @@ -5,7 +5,7 @@ declare module '*.svelte' { // Support using the component as both a class and function during the transition period // prettier-ignore - interface ComponentType { + export interface ComponentType { ( ...args: Parameters>> ): ReturnType, Record>> From e7bdd0cddb77125c4b4f9c931d5e52dbd5e83ebb Mon Sep 17 00:00:00 2001 From: Theodor Steiner Date: Mon, 11 Nov 2024 14:15:40 +0900 Subject: [PATCH 2/7] feat: update generated types --- packages/svelte/types/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/svelte/types/index.d.ts b/packages/svelte/types/index.d.ts index 00ba2556d9a1..7dba42a79976 100644 --- a/packages/svelte/types/index.d.ts +++ b/packages/svelte/types/index.d.ts @@ -2312,7 +2312,7 @@ declare module 'svelte/types/compiler/interfaces' { // Support using the component as both a class and function during the transition period // prettier-ignore - interface ComponentType { + export interface ComponentType { ( ...args: Parameters>> ): ReturnType, Record>> From a8728f839405ccf3aada23cd898e4af905966fd2 Mon Sep 17 00:00:00 2001 From: Theodor Steiner Date: Wed, 20 Nov 2024 21:49:06 +0900 Subject: [PATCH 3/7] refactor: move transitionary type to 'svelte/transitionary' --- packages/svelte/src/ambient.d.ts | 25 ++++++++++++++----------- packages/svelte/types/index.d.ts | 27 +++++++++++++++------------ 2 files changed, 29 insertions(+), 23 deletions(-) diff --git a/packages/svelte/src/ambient.d.ts b/packages/svelte/src/ambient.d.ts index 399a2dc60087..08c480d9ae73 100644 --- a/packages/svelte/src/ambient.d.ts +++ b/packages/svelte/src/ambient.d.ts @@ -1,17 +1,20 @@ +declare module 'svelte/transitionary' { + import { SvelteComponent, Component, type ComponentConstructorOptions } from 'svelte'; + // Support using the component as both a class and function during the transition period + // prettier-ignore + export interface TransitionaryComponentType { + ( + ...args: Parameters>> + ): ReturnType, Record>> + new (o: ComponentConstructorOptions): SvelteComponent + } +} declare module '*.svelte' { // use prettier-ignore for a while because of https://github.com/sveltejs/language-tools/commit/026111228b5814a9109cc4d779d37fb02955fb8b // prettier-ignore - import { SvelteComponent, Component, type ComponentConstructorOptions } from 'svelte' - - // Support using the component as both a class and function during the transition period - // prettier-ignore - export interface ComponentType { - ( - ...args: Parameters>> - ): ReturnType, Record>> - new (o: ComponentConstructorOptions): SvelteComponent - } - const Comp: ComponentType; + import { SvelteComponent } from 'svelte' + import { TransitionaryComponentType } from 'svelte/transitionary'; + const Comp: TransitionaryComponentType; type Comp = SvelteComponent; export default Comp; } diff --git a/packages/svelte/types/index.d.ts b/packages/svelte/types/index.d.ts index 7dba42a79976..5e574d17e8d8 100644 --- a/packages/svelte/types/index.d.ts +++ b/packages/svelte/types/index.d.ts @@ -2305,20 +2305,23 @@ declare module 'svelte/types/compiler/interfaces' { }; export {}; -}declare module '*.svelte' { - // use prettier-ignore for a while because of https://github.com/sveltejs/language-tools/commit/026111228b5814a9109cc4d779d37fb02955fb8b - // prettier-ignore - import { SvelteComponent, Component, type ComponentConstructorOptions } from 'svelte' - +}declare module 'svelte/transitionary' { + import { SvelteComponent, Component, type ComponentConstructorOptions } from 'svelte'; // Support using the component as both a class and function during the transition period // prettier-ignore - export interface ComponentType { - ( - ...args: Parameters>> - ): ReturnType, Record>> - new (o: ComponentConstructorOptions): SvelteComponent - } - const Comp: ComponentType; + export interface TransitionaryComponentType { + ( + ...args: Parameters>> + ): ReturnType, Record>> + new (o: ComponentConstructorOptions): SvelteComponent + } +} +declare module '*.svelte' { + // use prettier-ignore for a while because of https://github.com/sveltejs/language-tools/commit/026111228b5814a9109cc4d779d37fb02955fb8b + // prettier-ignore + import { SvelteComponent } from 'svelte' + import { TransitionaryComponentType } from 'svelte/transitionary'; + const Comp: TransitionaryComponentType; type Comp = SvelteComponent; export default Comp; } From ed6d299acdb76c944452fb952237fbda7ad26383 Mon Sep 17 00:00:00 2001 From: Theodor Steiner Date: Thu, 21 Nov 2024 01:42:13 +0900 Subject: [PATCH 4/7] refactor: implement LegacyComponentType in legacy-client module --- packages/svelte/src/ambient.d.ts | 15 ++------------ packages/svelte/src/legacy/legacy-client.js | 5 +++++ packages/svelte/types/index.d.ts | 23 ++++++++------------- 3 files changed, 16 insertions(+), 27 deletions(-) diff --git a/packages/svelte/src/ambient.d.ts b/packages/svelte/src/ambient.d.ts index 08c480d9ae73..fe87e446d602 100644 --- a/packages/svelte/src/ambient.d.ts +++ b/packages/svelte/src/ambient.d.ts @@ -1,20 +1,9 @@ -declare module 'svelte/transitionary' { - import { SvelteComponent, Component, type ComponentConstructorOptions } from 'svelte'; - // Support using the component as both a class and function during the transition period - // prettier-ignore - export interface TransitionaryComponentType { - ( - ...args: Parameters>> - ): ReturnType, Record>> - new (o: ComponentConstructorOptions): SvelteComponent - } -} declare module '*.svelte' { // use prettier-ignore for a while because of https://github.com/sveltejs/language-tools/commit/026111228b5814a9109cc4d779d37fb02955fb8b // prettier-ignore import { SvelteComponent } from 'svelte' - import { TransitionaryComponentType } from 'svelte/transitionary'; - const Comp: TransitionaryComponentType; + import { LegacyComponentType } from 'svelte/legacy'; + const Comp: LegacyComponentType; type Comp = SvelteComponent; export default Comp; } diff --git a/packages/svelte/src/legacy/legacy-client.js b/packages/svelte/src/legacy/legacy-client.js index c7684570bba7..19bdd6b08918 100644 --- a/packages/svelte/src/legacy/legacy-client.js +++ b/packages/svelte/src/legacy/legacy-client.js @@ -63,6 +63,11 @@ export function asClassComponent(component) { }; } +/** + * Support using the component as both a class and function during the transition period + * @typedef {{new: (o: ComponentConstructorOptions) => SvelteComponent} & ((...args: Parameters>>) => ReturnType, Record>>)} LegacyComponentType + */ + class Svelte4Component { /** @type {any} */ #events; diff --git a/packages/svelte/types/index.d.ts b/packages/svelte/types/index.d.ts index 5e574d17e8d8..e8ce22b08a11 100644 --- a/packages/svelte/types/index.d.ts +++ b/packages/svelte/types/index.d.ts @@ -1578,6 +1578,12 @@ declare module 'svelte/legacy' { * @deprecated Use this only as a temporary solution to migrate your automatically delegated events in Svelte 5. */ export function createBubbler(): (type: string) => (event: Event) => boolean; + /** + * Support using the component as both a class and function during the transition period + */ + export type LegacyComponentType = { + new: (o: ComponentConstructorOptions) => SvelteComponent; + } & ((...args: Parameters>>) => ReturnType, Record>>); /** * Substitute for the `trusted` event modifier * @deprecated @@ -2305,23 +2311,12 @@ declare module 'svelte/types/compiler/interfaces' { }; export {}; -}declare module 'svelte/transitionary' { - import { SvelteComponent, Component, type ComponentConstructorOptions } from 'svelte'; - // Support using the component as both a class and function during the transition period - // prettier-ignore - export interface TransitionaryComponentType { - ( - ...args: Parameters>> - ): ReturnType, Record>> - new (o: ComponentConstructorOptions): SvelteComponent - } -} -declare module '*.svelte' { +}declare module '*.svelte' { // use prettier-ignore for a while because of https://github.com/sveltejs/language-tools/commit/026111228b5814a9109cc4d779d37fb02955fb8b // prettier-ignore import { SvelteComponent } from 'svelte' - import { TransitionaryComponentType } from 'svelte/transitionary'; - const Comp: TransitionaryComponentType; + import { LegacyComponentType } from 'svelte/legacy'; + const Comp: LegacyComponentType; type Comp = SvelteComponent; export default Comp; } From 02c6d7f72ce2c4e6856b44da51e5800e0dacb283 Mon Sep 17 00:00:00 2001 From: Theodor Steiner Date: Thu, 21 Nov 2024 02:24:13 +0900 Subject: [PATCH 5/7] fix: ensure type check passes with jsdoc LegacyComponentType --- packages/svelte/src/legacy/legacy-client.js | 2 +- packages/svelte/types/index.d.ts | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/svelte/src/legacy/legacy-client.js b/packages/svelte/src/legacy/legacy-client.js index 19bdd6b08918..7ca202cf73bf 100644 --- a/packages/svelte/src/legacy/legacy-client.js +++ b/packages/svelte/src/legacy/legacy-client.js @@ -65,7 +65,7 @@ export function asClassComponent(component) { /** * Support using the component as both a class and function during the transition period - * @typedef {{new: (o: ComponentConstructorOptions) => SvelteComponent} & ((...args: Parameters>>) => ReturnType, Record>>)} LegacyComponentType + * @typedef {{new (o: ComponentConstructorOptions): SvelteComponent;(...args: Parameters>>): ReturnType, Record>>;}} LegacyComponentType */ class Svelte4Component { diff --git a/packages/svelte/types/index.d.ts b/packages/svelte/types/index.d.ts index e8ce22b08a11..01119e748572 100644 --- a/packages/svelte/types/index.d.ts +++ b/packages/svelte/types/index.d.ts @@ -1582,8 +1582,9 @@ declare module 'svelte/legacy' { * Support using the component as both a class and function during the transition period */ export type LegacyComponentType = { - new: (o: ComponentConstructorOptions) => SvelteComponent; - } & ((...args: Parameters>>) => ReturnType, Record>>); + new (o: ComponentConstructorOptions): SvelteComponent; + (...args: Parameters>>): ReturnType, Record>>; + }; /** * Substitute for the `trusted` event modifier * @deprecated From 23227e546df2470b54285c7c2e0f1837a4728239 Mon Sep 17 00:00:00 2001 From: Theodor Steiner Date: Fri, 22 Nov 2024 12:48:17 +0900 Subject: [PATCH 6/7] chore: add changeset --- .changeset/lovely-mayflies-sing.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/lovely-mayflies-sing.md diff --git a/.changeset/lovely-mayflies-sing.md b/.changeset/lovely-mayflies-sing.md new file mode 100644 index 000000000000..af3cfff8226d --- /dev/null +++ b/.changeset/lovely-mayflies-sing.md @@ -0,0 +1,5 @@ +--- +'svelte': patch +--- + +fix: export private legacy ComponentType From c4c544b41ae13d1a8f4229351cf4152d118fd285 Mon Sep 17 00:00:00 2001 From: Simon H <5968653+dummdidumm@users.noreply.github.com> Date: Fri, 22 Nov 2024 16:18:18 +0100 Subject: [PATCH 7/7] Update .changeset/lovely-mayflies-sing.md --- .changeset/lovely-mayflies-sing.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/lovely-mayflies-sing.md b/.changeset/lovely-mayflies-sing.md index af3cfff8226d..a9ced0b19ead 100644 --- a/.changeset/lovely-mayflies-sing.md +++ b/.changeset/lovely-mayflies-sing.md @@ -2,4 +2,4 @@ 'svelte': patch --- -fix: export private legacy ComponentType +fix: provide temporary `LegacyComponentType`