I know that <input type="number" /> has two value types: number | null, but svelte-check disagrees:
<script lang="ts">
export let value: number | null = null;
</script>
<input type="number" bind:value />
<!--
Type 'number | null' is not assignable to type 'string | number | string[] | undefined'.
Type 'null' is not assignable to type 'string | number | string[] | undefined'.
-->
This is confusing to me, because I tend to erase inputs by setting value to null and now I'm forced to resort to undefined.
You can test it yourself with the following REPL:
<script>
let value = 1;
</script>
<input bind:value type="number" />
<p>null: {value === null}</p>
<p>undefined: {value === undefined}</p>
<p>typeof: {typeof value}</p>
<button on:click={() => value = undefined}>undefined</button>
Technically speaking the error is correct because you cannot set null to the input. It will be converted to an empty string by the browser. But the bind: will convert it to null.. so yeah I guess we need to relax the typings here.
Most helpful comment
Technically speaking the error is correct because you cannot set
nullto the input. It will be converted to an empty string by the browser. But thebind:will convert it tonull.. so yeah I guess we need to relax the typings here.