Input type error with default values
So I have a couple inputs of type number that throw “expected string but got number” errors. This occurs when I submit a form populated with default values (from the db) for a user to edit, and submit the form without touching the numbered inputs.
If I edit the inputs before submitting the error doesn’t occur. All validation is of type number and the default values are also of type number.
Source: https://github.com/DollaHane/DearDegens/blob/main/src/components/pageEditMint/EditListing.tsx
GitHub
DearDegens/src/components/pageEditMint/EditListing.tsx at main · Do...
The next generation experience in public classified ads - DollaHane/DearDegens

4 Replies
multiple-amethyst•15mo ago
This is why:
https://github.com/DollaHane/DearDegens/blob/main/src/components/pageEditMint/EditListing.tsx#L629-L630
You've actively told TypeScript that "I do not care that this is not the type you're expecting" even though it's properly warning you that this bug will occur.
event.target.value
will be a string... Always.
Instead, try event.target.valueAsNumber
when you're using a number fieldGitHub
DearDegens/src/components/pageEditMint/EditListing.tsx at main · Do...
The next generation experience in public classified ads - DollaHane/DearDegens
generous-apricotOP•15mo ago
So the error disappeared in the editor, but the form still returns the same error in the DOM, and also returns an error after typing new values in the field 🤔
multiple-amethyst•15mo ago
I'd need a minimal reproduction to debug this further
generous-apricotOP•15mo ago
I’ve been doing a bit of searching online, stumbled into a bit of a rabbit hole. never knew numbered inputs in typescript were such a big deal. I’ll see if I can come up with something and update you 🙏🏼