diff --git a/.changeset/lovely-mayflies-sing.md b/.changeset/lovely-mayflies-sing.md new file mode 100644 index 000000000000..a9ced0b19ead --- /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 8a20a884ff1d..fe87e446d602 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 c7684570bba7..7ca202cf73bf 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 00ba2556d9a1..01119e748572 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; }