/Users/pablo/Library/Mobile Documents/com~apple~CloudDocs/pablion-files/arrow/Coding/Typescript/Type predicates
What is type predicates?#
- @2022-04-13
- type predicate is a (return) type
- From Official Documentation
-
To define a user-defined type guard, we simply need to define a function whose return type is a type predicate
How to use type predicates?#
- @2022-04-13
- Mostly used as type guard.
- Practice from Official Documentation
- Another example
Why use type predicates?#
- @2022-04-13
If you return a boolean the function will be a simple function that is not a typeguard. The pet is Fish syntax is what signals to the compiler that this function will impact the type of the argument.