Skip to content

Commit 3f57a38

Browse files
authored
Merge pull request #2 from basarat/master
Update from upstream repo basarat/typescript-book@master
2 parents f6c101b + fc3b4ca commit 3f57a38

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

docs/types/never.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Great. Now let's just jump into its key use case :)
2828

2929
# Use case: Exhaustive Checks
3030

31-
You can call never functions in a never context
31+
You can call never functions in a never context.
3232

3333
```ts
3434
function foo(x: string | number): boolean {
@@ -43,10 +43,10 @@ function foo(x: string | number): boolean {
4343
// - Or Unreachable code detected
4444
// But because typescript understands that `fail` function returns `never`
4545
// It can allow you to call it as you might be using it for runtime safety / exhaustive checks.
46-
fail("Unexhaustive!");
46+
return fail("Unexhaustive!");
4747
}
4848

49-
function fail(message: string) { throw new Error(message); }
49+
function fail(message: string): never { throw new Error(message); }
5050
```
5151

5252
And because `never` is only assignable to another `never` you can use it for *compile time* exhaustive checks as well. This is covered in the [*discriminated union* section](./discriminated-unions.md).

0 commit comments

Comments
 (0)