<input type='number' /> value isn't parsed as a number when `type='number'` attribute is spread instead of being explicitly written
See original GitHub issueDescribe 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:
- Created 3 years ago
- Comments:8 (7 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
It’s technically impossible. It’s not just spread attributes, it’s any
type
attribute that could potentially change at runtime, as seen here: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.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 whentype
is set by a spread) then it would need to include the relevant handling fortype=text
,type=number
,type=radio
,type=checkbox
, etc.