Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typescript control flow analysis information is not persisted in Slot props #8751

Closed
mlschmidt366 opened this issue Jun 17, 2023 · 2 comments

Comments

@mlschmidt366
Copy link

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 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?

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

npm: v9.6.4
typescript: v5.0.4
svelte: v3.59.1
svelte-check: v3.3.2

Severity

annoyance

@jasonlyu123
Copy link
Member

Duplicate of sveltejs/language-tools#1832

@mlschmidt366
Copy link
Author

Thanks, I wasn't aware of the language-tools repository. There I found also an open issue related to two-way binding type safety, which I am (ab-)using in my current workaround for this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants