From e721d96d32ccbea5961f491a4349f71e57b15cd1 Mon Sep 17 00:00:00 2001 From: Theodor Steiner <40017636+Theo-Steiner@users.noreply.github.com> Date: Sat, 23 Nov 2024 00:22:05 +0900 Subject: [PATCH] fix: export temporary LegacyComponentType (#14256) (#14257) closes #14256 helps TypeScript when generating dts files to not fail --- .changeset/lovely-mayflies-sing.md | 5 +++++ packages/svelte/src/ambient.d.ts | 14 +++----------- packages/svelte/src/legacy/legacy-client.js | 5 +++++ packages/svelte/types/index.d.ts | 21 ++++++++++----------- 4 files changed, 23 insertions(+), 22 deletions(-) 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 0000000000..a9ced0b19e --- /dev/null +++ b/.changeset/lovely-mayflies-sing.md @@ -0,0 +1,5 @@ +--- +'svelte': patch +--- + +fix: provide temporary `LegacyComponentType` diff --git a/packages/svelte/src/ambient.d.ts b/packages/svelte/src/ambient.d.ts index 8a20a884ff..fe87e446d6 100644 --- a/packages/svelte/src/ambient.d.ts +++ b/packages/svelte/src/ambient.d.ts @@ -1,17 +1,9 @@ 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 - interface ComponentType { - ( - ...args: Parameters>> - ): ReturnType, Record>> - new (o: ComponentConstructorOptions): SvelteComponent - } - const Comp: ComponentType; + import { SvelteComponent } from 'svelte' + 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 9e1cd888ad..3715617f4c 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 00ba2556d9..01119e7485 100644 --- a/packages/svelte/types/index.d.ts +++ b/packages/svelte/types/index.d.ts @@ -1578,6 +1578,13 @@ 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 @@ -2308,17 +2315,9 @@ declare module 'svelte/types/compiler/interfaces' { }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 - interface ComponentType { - ( - ...args: Parameters>> - ): ReturnType, Record>> - new (o: ComponentConstructorOptions): SvelteComponent - } - const Comp: ComponentType; + import { SvelteComponent } from 'svelte' + import { LegacyComponentType } from 'svelte/legacy'; + const Comp: LegacyComponentType; type Comp = SvelteComponent; export default Comp; }