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
Notice that value has type number | null because it becomes null when the user clears the contents of the input field.
Now I use that component inside MyForm.svelte as follows:
<scriptlang="ts">
importNumberInputfrom'./NumberInput.svelte';let quantity =1;
</script>
<NumberInputbind:value={quantity} />
<!-- ^^^^^^^^ I would like to see an error here.-->
Here quantity has type number.
Currently this code does not produce any type errors. That's problematic because the two way binding may set quantity to null at runtime, and it's hard to see that from within MyForm.svelte.
Proposed solution
I'd like to see a type error at the specified location because quantity has type number whereas value has type number | null.
I would fix the type error inside MyForm.svelte as follows:
let quantity: number | null = 1;
Alternate solutions
Perhaps the type of quantity could be inferred to be number | null. I'm not sure though.
I'm open to other approaches or other advice on how people have solved similar issues.
The text was updated successfully, but these errors were encountered:
Problem
Let's say I have a
NumberInput.svelte
component which accepts user input, somewhat like<input type="number"/>
Notice that
value
has typenumber | null
because it becomesnull
when the user clears the contents of the input field.Now I use that component inside
MyForm.svelte
as follows:Here
quantity
has typenumber
.Currently this code does not produce any type errors. That's problematic because the two way binding may set
quantity
tonull
at runtime, and it's hard to see that from withinMyForm.svelte
.Proposed solution
I'd like to see a type error at the specified location because
quantity
has typenumber
whereasvalue
has typenumber | null
.I would fix the type error inside
MyForm.svelte
as follows:Alternate solutions
quantity
could be inferred to benumber | null
. I'm not sure though.The text was updated successfully, but these errors were encountered: