diff --git a/.changeset/chilly-laws-juggle.md b/.changeset/chilly-laws-juggle.md new file mode 100644 index 0000000000..9f7c4b89d9 --- /dev/null +++ b/.changeset/chilly-laws-juggle.md @@ -0,0 +1,5 @@ +--- +"svelte": patch +--- + +fix: relax `Component` type diff --git a/packages/svelte/src/index.d.ts b/packages/svelte/src/index.d.ts index 71c180d522..49207da0d5 100644 --- a/packages/svelte/src/index.d.ts +++ b/packages/svelte/src/index.d.ts @@ -129,7 +129,7 @@ export class SvelteComponent< export interface Component< Props extends Record = {}, Exports extends Record = {}, - Bindings extends keyof Props | '' = '' + Bindings extends keyof Props | '' = string > { /** * @param internal An internal object used by Svelte. Do not use or modify. diff --git a/packages/svelte/tests/types/component.ts b/packages/svelte/tests/types/component.ts index b240d4a4be..047363947b 100644 --- a/packages/svelte/tests/types/component.ts +++ b/packages/svelte/tests/types/component.ts @@ -204,6 +204,8 @@ const functionComponent: Component< }; functionComponent.element === HTMLElement; +const bindingIsOkayToWiden: Component = functionComponent; + functionComponent(null as any, { binding: true, // @ts-expect-error diff --git a/packages/svelte/types/index.d.ts b/packages/svelte/types/index.d.ts index ee42b58ec4..acc19259c3 100644 --- a/packages/svelte/types/index.d.ts +++ b/packages/svelte/types/index.d.ts @@ -126,7 +126,7 @@ declare module 'svelte' { export interface Component< Props extends Record = {}, Exports extends Record = {}, - Bindings extends keyof Props | '' = '' + Bindings extends keyof Props | '' = string > { /** * @param internal An internal object used by Svelte. Do not use or modify. @@ -1990,7 +1990,7 @@ declare module 'svelte/legacy' { * * */ export function createClassComponent, Exports extends Record, Events extends Record, Slots extends Record>(options: import("svelte").ComponentConstructorOptions & { - component: import("svelte").ComponentType> | import("svelte").Component; + component: import("svelte").ComponentType> | import("svelte").Component; immutable?: boolean | undefined; hydrate?: boolean | undefined; recover?: boolean | undefined; @@ -2001,7 +2001,7 @@ declare module 'svelte/legacy' { * @deprecated Use this only as a temporary solution to migrate your imperative component code to Svelte 5. * * */ - export function asClassComponent, Exports extends Record, Events extends Record, Slots extends Record>(component: import("svelte").SvelteComponent | import("svelte").Component): import("svelte").ComponentType & Exports>; + export function asClassComponent, Exports extends Record, Events extends Record, Slots extends Record>(component: import("svelte").SvelteComponent | import("svelte").Component): import("svelte").ComponentType & Exports>; /** * Runs the given function once immediately on the server, and works like `$effect.pre` on the client. *