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
The non-null assertion operator or for short (!) doesn't work when passing direct props to a component.
Note that it works fine when used inside a callback passed as a prop.
Reproduction
let's say we have the following simple component that expects a prop.
<svelte:optionsrunes />
<scriptlang="ts">
importSimpleComponentfrom"$components/test/test.svelte";let simpleString:string|undefined=$state("just some value");
</script>
<SimpleComponentstring={simpleString!}>hello</SimpleComponent>
Now here typescript will tell us that simpleString can be undefined and thus not assignable to the string prop which is of type string only. But I know that simpleString has a default value so I want to use the non-null assertion operator but it doesn't seem to work in this specific case. It is simply ignored
Not sure why this is happening, the generated output preserves the !, so it should work, and if I paste the generated output into a .ts file I see no error - strange.
Edit: It is missing when setting emitOnTemplateError to true, which is the case for the language server.
Describe the bug
The non-null assertion operator or for short
(!)
doesn't work when passing direct props to a component.Note that it works fine when used inside a callback passed as a prop.
Reproduction
let's say we have the following simple component that expects a prop.
And then in our page, we render it like so
Now here typescript will tell us that simpleString can be undefined and thus not assignable to the string prop which is of type string only. But I know that simpleString has a default value so I want to use the non-null assertion operator but it doesn't seem to work in this specific case. It is simply ignored
Logs
No response
System Info
Severity
annoyance
The text was updated successfully, but these errors were encountered: