Skip to content

Commit 63e5831

Browse files
committed
fix: adjust mount and createRoot types
they expect the component constructor, not the instance
1 parent a3bc7d5 commit 63e5831

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

.changeset/green-eggs-approve.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
fix: adjust mount and createRoot types

packages/svelte/src/internal/client/render.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2915,7 +2915,7 @@ export function unwrap(value) {
29152915
* @template {Record<string, any>} Props
29162916
* @template {Record<string, any> | undefined} Exports
29172917
* @template {Record<string, any>} Events
2918-
* @param {import('../../main/public.js').SvelteComponent<Props, Events>} component
2918+
* @param {typeof import('../../main/public.js').SvelteComponent<Props, Events>} component
29192919
* @param {{
29202920
* target: Node;
29212921
* props?: Props;
@@ -3034,7 +3034,7 @@ export function createRoot(component, options) {
30343034
* @template {Record<string, any>} Props
30353035
* @template {Record<string, any> | undefined} Exports
30363036
* @template {Record<string, any>} Events
3037-
* @param {import('../../main/public.js').SvelteComponent<Props, Events>} component
3037+
* @param {typeof import('../../main/public.js').SvelteComponent<Props, Events>} component
30383038
* @param {{
30393039
* target: Node;
30403040
* props?: Props;

packages/svelte/tests/types/component.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import {
44
SvelteComponent,
55
type ComponentEvents,
66
type ComponentProps,
7-
type ComponentType
7+
type ComponentType,
8+
mount
89
} from 'svelte';
910

1011
// --------------------------------------------------------------------------- legacy: classes
@@ -103,7 +104,22 @@ const newComponentEvents2: ComponentEvents<NewComponent> = {
103104
event: new KeyboardEvent('click')
104105
};
105106

106-
const instance = createRoot(newComponent, {
107+
mount(NewComponent, {
108+
target: null as any as Document | Element | ShadowRoot | Text | Comment,
109+
props: {
110+
prop: 'foo',
111+
// @ts-expect-error
112+
x: ''
113+
},
114+
events: {
115+
event: new MouseEvent('click')
116+
},
117+
immutable: true,
118+
intro: false,
119+
recover: false
120+
});
121+
122+
const instance = createRoot(NewComponent, {
107123
target: null as any as Document | Element | ShadowRoot | Text | Comment,
108124
props: {
109125
prop: 'foo',

0 commit comments

Comments
 (0)