We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
We could improve compile-time checks provided by the TypeScript compiler introducing the unreachable function:
unreachable
export function unreachable(value: never): never { throw InternalException.make(`Reached impossible case`, { node: value }); }
It accepts the parameter never, so it could be used to perform a static exhaustiveness checks for switch clauses:
never
switch
switch (node.kind) { case "id": // ... // other cases default: unreachable(node); }
If some of the node kinds are not covered by the case clauses, we'll get a compilation error:
case
That's quite useful especially to avoid regressions when changing enum types implementations.
The text was updated successfully, but these errors were encountered:
That's what TypeScript devs do in its compiler, so it seems to be as close to a recommended approach as it gets.
I looked up how they intend to use it, and results were quite inconclusive: they use it standalone, with return and even with throw in front.
return
throw
EDIT. There's a lot of other shiny functions in that file too...
Sorry, something went wrong.
verytactical
Successfully merging a pull request may close this issue.
We could improve compile-time checks provided by the TypeScript compiler introducing the
unreachable
function:It accepts the parameter
never
, so it could be used to perform a static exhaustiveness checks forswitch
clauses:If some of the node kinds are not covered by the
case
clauses, we'll get a compilation error:That's quite useful especially to avoid regressions when changing enum types implementations.
The text was updated successfully, but these errors were encountered: