arktypea
arktype17mo ago
PIat

Accept number in string type

Hello! I'm parsing each value in a form with JSON.parse to convert string values like
false
to actual booleans. Unfortunately, this introduces the issue, that if someone inputs 123 into a text field, it gets parsed into a number type by JSON.parse. Then if the field is type string. An error is thrown, since number is not assignable to string.

How should a type look like, if it should handle such a situation?
Was this page helpful?