diff --git a/packages/documentation/copy/en/handbook-v2/Narrowing.md b/packages/documentation/copy/en/handbook-v2/Narrowing.md index 34044be7c6f5..2c1acd4df153 100644 --- a/packages/documentation/copy/en/handbook-v2/Narrowing.md +++ b/packages/documentation/copy/en/handbook-v2/Narrowing.md @@ -415,7 +415,9 @@ function example() { ## Using type predicates -We've worked with existing JavaScript constructs to handle narrowing so far, however sometimes you want more direct control over how types change throughout your code. +We've worked with existing JavaScript constructs to handle narrowing so far, however sometimes you want more direct control over how types change throughout your code. Type predicates provide a way to perform type narrowing in scenarios where the TypeScript compiler is *unable* to do so. + +Type predicates bypass the TypeScript compiler's type checking. This means that they can be used to change a value's type to an incorrect type. **Type predicates should be a last resort for narrowing that cannot be done any other way.** To define a user-defined type guard, we simply need to define a function whose return type is a _type predicate_: @@ -483,6 +485,11 @@ In addition, classes can [use `this is Type`](/docs/handbook/2/classes.html#this Types can also be narrowed using [Assertion functions](/docs/handbook/release-notes/typescript-3-7.html#assertion-functions). +As with [type predicates](#using-type-predicates), assertion functions provide a way to perform type narrowing in scenarios where the TypeScript compiler is *unable* to do so. + +Assertion functions bypass the TypeScript compiler's type checking. This means that they can be used to change a value's type to an incorrect type. **Assertion functions should be a last resort for narrowing that cannot be done any other way.** + + # Discriminated unions Most of the examples we've looked at so far have focused around narrowing single variables with simple types like `string`, `boolean`, and `number`.