-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Closed as not planned
Description
Describe the bug
It appears that tsc doesn't accept the line:
const mounted: MyComponent = mount(MyComponent, { target: div })with a type error. The following, however, works:
const mounted: MyComponent = mount(MyComponent, { target: div }) as MyComponentReproduction
The issue somehow cannot be reproduce in the svelte playground (attempt here), so I've created a repo showcasing the issue: https://github.com/Nearoo/svelte-mount-issue
If you prefer to recreate locally, do:
npm create vite@latest -> Svelte -> TypeScript- copy over
App.svelteandMyComponent.svelte
Run npm run check, and you'll get the following output:
.../src/App.svelte:7:11
Error: Type '{ sayHello: (name: string) => void; } & { $set?: any; $on?: any; }' is not assignable to type 'SvelteComponent<{ sayHello?: ((name: string) => void) | undefined; }, { [evt: string]: CustomEvent<any>; }, {}> & { $$bindings?: string | undefined; } & { ...; }'.
Type '{ sayHello: (name: string) => void; } & { $set?: any; $on?: any; }' is missing the following properties from type 'SvelteComponent<{ sayHello?: ((name: string) => void) | undefined; }, { [evt: string]: CustomEvent<any>; }, {}>': $$prop_def, $$events_def, $$slot_def, $destroy (ts)
onMount(() => {
const mounted: MyComponent = mount(MyComponent, { target: div })
})
====================================
svelte-check found 1 error and 0 warnings in 1 file
Logs
No response
System Info
Just posting package.json:
{
"name": "mount-ts-issue",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "vite build",
"preview": "vite preview",
"check": "svelte-check --tsconfig ./tsconfig.json && tsc -p tsconfig.node.json"
},
"devDependencies": {
"@sveltejs/vite-plugin-svelte": "^4.0.0",
"@tsconfig/svelte": "^5.0.4",
"svelte": "^5.1.3",
"svelte-check": "^4.0.5",
"tslib": "^2.8.0",
"typescript": "^5.6.3",
"vite": "^5.4.10"
}
}Severity
annoyance
Metadata
Metadata
Assignees
Labels
No labels