From 63e58318460dbb3485df93d15beb2779a86d2c9a Mon Sep 17 00:00:00 2001 From: Simon Holthausen Date: Fri, 24 Nov 2023 16:36:04 +0100 Subject: [PATCH] fix: adjust mount and createRoot types they expect the component constructor, not the instance --- .changeset/green-eggs-approve.md | 5 +++++ packages/svelte/src/internal/client/render.js | 4 ++-- packages/svelte/tests/types/component.ts | 20 +++++++++++++++++-- 3 files changed, 25 insertions(+), 4 deletions(-) create mode 100644 .changeset/green-eggs-approve.md diff --git a/.changeset/green-eggs-approve.md b/.changeset/green-eggs-approve.md new file mode 100644 index 0000000000..90c7ec357e --- /dev/null +++ b/.changeset/green-eggs-approve.md @@ -0,0 +1,5 @@ +--- +'svelte': patch +--- + +fix: adjust mount and createRoot types diff --git a/packages/svelte/src/internal/client/render.js b/packages/svelte/src/internal/client/render.js index a86c05a616..afb060639a 100644 --- a/packages/svelte/src/internal/client/render.js +++ b/packages/svelte/src/internal/client/render.js @@ -2915,7 +2915,7 @@ export function unwrap(value) { * @template {Record} Props * @template {Record | undefined} Exports * @template {Record} Events - * @param {import('../../main/public.js').SvelteComponent} component + * @param {typeof import('../../main/public.js').SvelteComponent} component * @param {{ * target: Node; * props?: Props; @@ -3034,7 +3034,7 @@ export function createRoot(component, options) { * @template {Record} Props * @template {Record | undefined} Exports * @template {Record} Events - * @param {import('../../main/public.js').SvelteComponent} component + * @param {typeof import('../../main/public.js').SvelteComponent} component * @param {{ * target: Node; * props?: Props; diff --git a/packages/svelte/tests/types/component.ts b/packages/svelte/tests/types/component.ts index 13ebb65753..1047d56781 100644 --- a/packages/svelte/tests/types/component.ts +++ b/packages/svelte/tests/types/component.ts @@ -4,7 +4,8 @@ import { SvelteComponent, type ComponentEvents, type ComponentProps, - type ComponentType + type ComponentType, + mount } from 'svelte'; // --------------------------------------------------------------------------- legacy: classes @@ -103,7 +104,22 @@ const newComponentEvents2: ComponentEvents = { event: new KeyboardEvent('click') }; -const instance = createRoot(newComponent, { +mount(NewComponent, { + target: null as any as Document | Element | ShadowRoot | Text | Comment, + props: { + prop: 'foo', + // @ts-expect-error + x: '' + }, + events: { + event: new MouseEvent('click') + }, + immutable: true, + intro: false, + recover: false +}); + +const instance = createRoot(NewComponent, { target: null as any as Document | Element | ShadowRoot | Text | Comment, props: { prop: 'foo',