Skip to content

Commit

Permalink
fix: adjust mount and createRoot types
Browse files Browse the repository at this point in the history
they expect the component constructor, not the instance
  • Loading branch information
dummdidumm committed Nov 24, 2023
1 parent a3bc7d5 commit 63e5831
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/green-eggs-approve.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

fix: adjust mount and createRoot types
4 changes: 2 additions & 2 deletions packages/svelte/src/internal/client/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -2915,7 +2915,7 @@ export function unwrap(value) {
* @template {Record<string, any>} Props
* @template {Record<string, any> | undefined} Exports
* @template {Record<string, any>} Events
* @param {import('../../main/public.js').SvelteComponent<Props, Events>} component
* @param {typeof import('../../main/public.js').SvelteComponent<Props, Events>} component
* @param {{
* target: Node;
* props?: Props;
Expand Down Expand Up @@ -3034,7 +3034,7 @@ export function createRoot(component, options) {
* @template {Record<string, any>} Props
* @template {Record<string, any> | undefined} Exports
* @template {Record<string, any>} Events
* @param {import('../../main/public.js').SvelteComponent<Props, Events>} component
* @param {typeof import('../../main/public.js').SvelteComponent<Props, Events>} component
* @param {{
* target: Node;
* props?: Props;
Expand Down
20 changes: 18 additions & 2 deletions packages/svelte/tests/types/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import {
SvelteComponent,
type ComponentEvents,
type ComponentProps,
type ComponentType
type ComponentType,
mount
} from 'svelte';

// --------------------------------------------------------------------------- legacy: classes
Expand Down Expand Up @@ -103,7 +104,22 @@ const newComponentEvents2: ComponentEvents<NewComponent> = {
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',
Expand Down

1 comment on commit 63e5831

@vercel
Copy link

@vercel vercel bot commented on 63e5831 Nov 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

svelte-5-preview – ./sites/svelte-5-preview

svelte-octane.vercel.app
svelte-5-preview-git-main-svelte.vercel.app
svelte-5-preview.vercel.app
svelte-5-preview-svelte.vercel.app

Please sign in to comment.