-
Notifications
You must be signed in to change notification settings - Fork 27
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
Generate user-defined type guards #40
Comments
Interesting idea. In my experience, TypeScript understands discriminated unions perfectly well without explicit type guards. I.e. if (u.tag === "A") {
// Now TSC knows u is an A
} I have no real objection to this feature, though it would only make sense with the I'd be curious about when you'd want this over the normal |
Indeed.
Partially stylistic, partially I triggered a bug where one of the checkers I'm using is complaining that
I'd expect it to be optional. |
Huh, what checker?
As in, on a per-type basis? Perhaps opted into in the |
Quoth the relevant
And yeah, |
A few more notes: Seems to be something the Svelte community is working on: sveltejs/svelte#9130 After further thought, adding formatting-type options in the Another alternative would be to do it at the formatting level, by adding an option to If you need this immediately, I'd recommend using the |
At this point I'm using |
In cases where a sum type is transcribed as a series of interfaces and a union type:
Type predicates (https://www.typescriptlang.org/docs/handbook/2/narrowing.html#using-type-predicates) would be useful:
The text was updated successfully, but these errors were encountered: