From a4fc4778241048e4b04bb60d811ef0798426075e Mon Sep 17 00:00:00 2001 From: Ivan Novikov Date: Sat, 19 Dec 2020 11:48:37 -0500 Subject: [PATCH] docs(asNever): minor edits to docstring --- src/internal/types/asNever.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/internal/types/asNever.ts b/src/internal/types/asNever.ts index ad600f3..4601d7d 100644 --- a/src/internal/types/asNever.ts +++ b/src/internal/types/asNever.ts @@ -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.';