You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Typescript in svelte already supports control flow analysis when using {#if varName} statements in the html section of a component. The typescript compiler understands that inside the if-block, the variable is neither null nor undefined.
However, when passing the variable to a slot inside the if-block, Typescript shows that the variable might be null or undefined when the slot property is used in another component.
A workaround for my use case, where I am trying to wrap a component whose children should only be populated once the parent component has mounted, there is a workaround to simply set the wrapper type not to be null or undefined, but the typing seems to be incorrect. I believe that might be another bug, which allows two variables that are bound using component binding to be of different types?
Note: REPL doesn't compile due to lacking TypeScript support, but you can download the code and test it locally by running npx svelte-check or in VS Code using the "Svelte for VS Code" Extension.
Describe the bug
Typescript in svelte already supports control flow analysis when using
{#if varName}
statements in the html section of a component. The typescript compiler understands that inside theif
-block, the variable is neithernull
norundefined
.However, when passing the variable to a slot inside the
if
-block, Typescript shows that the variable might benull
orundefined
when the slot property is used in another component.A workaround for my use case, where I am trying to wrap a component whose children should only be populated once the parent component has mounted, there is a workaround to simply set the wrapper type not to be
null
orundefined
, but the typing seems to be incorrect. I believe that might be another bug, which allows two variables that are bound using component binding to be of different types?Reproduction
https://svelte.dev/repl/e3e71ae0b9714eaf8a03c8c2ca65f507?version=3.59.1
Note: REPL doesn't compile due to lacking TypeScript support, but you can download the code and test it locally by running
npx svelte-check
or in VS Code using the "Svelte for VS Code" Extension.Logs
No response
System Info
Severity
annoyance
The text was updated successfully, but these errors were encountered: