You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Adding | null alternative significantly degrades verboseness of the error message.
Example:
createAssertType<{data: {node: {a: string;closed: string;b: string}|null;};}>()({data: {node: {a: "a",closed: false,b: "b"}}});// Result:// TypeGuardError: validation failed at $.data.node: there are no valid alternatives
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:
createAssertType<{data: {node: {a: string;closed: string;b: string};};}>()({data: {node: {a: "a",closed: false,b: "b"}}});// Result:// TypeGuardError: validation failed at $.data.node.closed: expected a string
Is it (at least theoretically) possible to improve error messages here? The case when | null or | undefined or field?: type are used is pretty common (e.g. in GraphQL responses, the field is often times nullable).