question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

<input type='number' /> value isn't parsed as a number when `type='number'` attribute is spread instead of being explicitly written

See original GitHub issue

Describe the bug An input like <input type='number' /> will parse the value as a number, however if you were to spread the type='number' onto the input it will be parsed as a string instead

Logs N/A

To Reproduce https://svelte.dev/repl/1d4158ad6d4f4203a7fe2bfbfa4c05ec?version=3.23.2

Expected behavior Regardless of spreading the type='number' attribute or explicitly defining it, both should result in the value being parsed as a number.

Stacktraces N/A

Information about your Svelte project: REPL link uses v3.23.2

Severity There is a work around, and that’s to explicitly put the type='number' attribute. It’s just annoying that I can’t use the spread and results in a lot of duplication.

Additional context N/A

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
Rich-Harriscommented, Jun 19, 2020

It’s technically impossible. It’s not just spread attributes, it’s any type attribute that could potentially change at runtime, as seen here:

Screen Shot 2020-06-19 at 9 50 59 AM

The only potential solution (which isn’t something that’s currently on the roadmap, though the roadmap is always subject to change!) is to allow people to opt in to chunkier bundles in cases where type is dynamic. Not sure exactly what that would look like in terms of syntax etc; either way that should probably be a new issue, if someone were to raise it.

1reaction
Conduitrycommented, Jun 18, 2020

The bundle size would be increased. If the compiler can’t tell at compile time what the type of an <input> is (which it can’t when type is set by a spread) then it would need to include the relevant handling for type=text, type=number, type=radio, type=checkbox, etc.

Read more comments on GitHub >

github_iconTop Results From Across the Web

<input type="number"> - HTML: HyperText Markup Language
<input> elements of type number are used to let the user enter a number. They include built-in validation to reject non-numerical entries.
Read more >
HTML input type="number" still returning a string when ...
When you set input type="number" then these input field don't accept non numeric input but at the same time it doesn't make the...
Read more >
Why the number input is the worst input - Stack Overflow Blog
When the number input contains an invalid value and you retrieve the value, you get a blank string. Valid numbers include more than...
Read more >
Documentation - Narrowing - TypeScript
Understand how TypeScript uses JavaScript knowledge to reduce the amount of type syntax in your projects.
Read more >
GraphQL specification
This example describes a valid complete GraphQL schema, despite not explicitly including a schema definition. The Query type is presumed to be the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found