Steve - Would this be valid, or would it possib...
Would this be valid, or would it possibly parse data as unknown while there could be a more specific match?
Solution:Jump to solution
order matters in union definitions (they're run in series one after the other), so as long as you put the more specific ones first, it'll match the more specific ones and not the unknown one.
3 Replies
Solution
order matters in union definitions (they're run in series one after the other), so as long as you put the more specific ones first, it'll match the more specific ones and not the unknown one.
The actual type you get from this is going to be annoying to deal with in that it cannot be a discriminated union on the dataType given that it'll be
| string
.
I've dealt with similar issues before by parsing without the unknown fallthrough and doing a second parse with the unknown fallthrough in the error case. That keeps the happy-path with a nice type, and the unhappy path is still relatively loose, while still catching structural issues overall.@Scott Trinh refactored a bit, got something valid out
PS we are making it to the deadline 🙂