-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
More detailed error message for "Xyz | null" cases (not just "there are no valid alternatives") #56
Comments
@woutervh- If you're positive on this |
Yes, in theory it's possible to improve the error messages. But to me it's not entirely clear what should be reported in the error message. One idea I had is to report the problem with each alternative in the type unions, but this can rapidly grow the error message in size and complexity. Especially when there are nested alternatives, does each possible branch need to be reported? Any input on some sensible error reporting would be appreciated. |
Since I.e. in this particular snippet: const data = { data: { node: { a: "a", closed: false, b: "b" } } }
createAssertType<{
data: {
node: { a: string; closed: string; b: string } | null;
};
}>()(data); the updated logic in the lambda might be:
|
It's an interesting idea, doing it just for |
@woutervh- Please review this PR https://github.com/woutervh-/typescript-is/pull/96 that partially fixes this issue. Thank you! |
Fix #56: Better error messages for nullable types
Released |
@woutervh- Oh wow, thanks a lot! BTW, the credit should've been given to @oleg-slapdash oleg-slapdash who prepared that PR, not to me. |
Adding
| null
alternative significantly degrades verboseness of the error message.Example:
Notice that it doesn't mention the name of the mis-typed field ("closed"), so it's pretty hard to debug, what's the problem (especially when there is a lot of fields).
If I remove
| null
clause, it starts showing the field name:Is it (at least theoretically) possible to improve error messages here? The case when
| null
or| undefined
orfield?: type
are used is pretty common (e.g. in GraphQL responses, the field is often times nullable).The text was updated successfully, but these errors were encountered: