The third video in our TypeScript Narrowing series. In this video, I explain:
Type predicates
How to create custom type guards
BONUS: How to create a type guard by exclusion
📚 Read the article: https://www.lucaspaganini.com/academy...
🚨 Subscribe to the newsletter: https://www.lucaspaganini.com/newsletter
📧 Email: [email protected]
🐦 Twitter: / lucaspaganini
📸 Instagram: / lucaspaganini
----------
CHAPTERS
0:00 Introduction
0:36 Type Predicates
2:16 The unknown Type
2:33 Custom Guards
2:46 Error Guard
2:53 Warning Guard
3:31 Falsy Guard
4:24 formatErrorMessage() with Custom Guards
4:29 BONUS: Narrowing by Exclusion
4:46 Truthy Guard
4:59 Conclusion
RELATED
1. 1min JS - Falsy and Truthy: • Falsy and Truthy in JavaScript
2. 1min TS - Unknown vs Any: • Unknown vs Any in TypeScript - With Examples
3. TypeScript Narrowing Series: • What is a Type Guard - TypeScript Narrowin...
4. TypeScript Narrowing Part 1 - What is a Type Guard: • What is a Type Guard - TypeScript Narrowin...
5. TypeScript Narrowing Part 2 - Type Guard Operators: • Fundamental Type Guards - TypeScript Narro...
REFERENCES
1. TypeScript docs on narrowing: https://www.typescriptlang.org/docs/h...
2. TypeScript docs type predicates: https://www.typescriptlang.org/docs/h...
3. The in operator on MDN: https://developer.mozilla.org/en-US/d...
4. TypeScript proposal to add NaN as a type: https://github.com/Microsoft/TypeScri...
#typescript #programming #webdevelopment