Skip to content

Commit

Permalink
docs(asNever): minor edits to docstring
Browse files Browse the repository at this point in the history
  • Loading branch information
ivan7237d committed Dec 19, 2020
1 parent a1c3187 commit a4fc477
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/internal/types/asNever.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
/**
* A utility used to typecheck that a symbol has type `never`. Throws if called.
* A utility used to typecheck that a symbol has type `never` and therefore the
* call site is unreachable. Throws if called.
*
* Example: if `a` has type `0 | 1`, you could write `a === 0 ? 'zero' : a === 1
* ? 'one' : asNever(a)` to make sure that typecheck will fail if the type of
* `a` changes to say `0 | 1 | 2`.
* ? 'one' : asNever(a)` to make sure that all possibilities for `a` have been
* exhausted. If the type of `a` changes to say `0 | 1 | 2`, the type of the
* argument passed to `asNever` will be inferred as `2`, and this will cause a
* typechecking error because the only type assignable to `never` is `never`
* itself.
*/
export const asNever: (arg: never) => never = () => {
throw 'asNever has been called; this means that if you use TypeScript, typecheck is failing.';
Expand Down

0 comments on commit a4fc477

Please sign in to comment.