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

No null in bind:value type for input type="number" #849

Closed
non25 opened this issue Mar 2, 2021 · 1 comment
Closed

No null in bind:value type for input type="number" #849

non25 opened this issue Mar 2, 2021 · 1 comment
Labels
bug Something isn't working Fixed Fixed in master branch. Pending production release.

Comments

@non25
Copy link

non25 commented Mar 2, 2021

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>
@dummdidumm
Copy link
Member

dummdidumm commented Mar 3, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Fixed Fixed in master branch. Pending production release.
Projects
None yet
Development

No branches or pull requests

2 participants