Link to coupons with BIG DISCOUNTS 🤯 :
👉 Mastering Terraform: From Beginner to Expert - https://www.lauromueller.com/courses/...
👉 Mastering GitHub Actions: From Beginner to Expert - https://www.lauromueller.com/courses/...
👉 Write better code: 20 code smells and how to get rid of them - https://www.lauromueller.com/courses/...
Do you want to bring your dev skills to the next level? Then check out the links with BIG DISCOUNTS to my courses on Udemy! Purchasing the courses is a great way to support this channel and the content I produce, while also getting something amazing in return, so head there right now! I am looking forward to seeing you there and receiving your feedback on the course!
The courses also have a 30-day money-back guarantee, so if you are not satisfied with the purchase, you can ask for a refund, no questions asked.
***
Hello everyone! In this video, we focus on type unions and type intersections in TypeScript. This is a very powerful concept, but we need to fully understand how TypeScript interprets the resulting types.
Chapters:
0:00 Introduction
1:11 Type unions in TypeScript
8:35 Type intersections in TypeScript
17:59 Summary
22:16 Closing
Summary:
Type unions and type intersections allow you to combine interfaces and type aliases in different ways to create new types in TypeScript. Both concepts need to be approached from two sides: the universe of objects, or values, which satisfy the resulting type constraint, and the universe of properties of the resulting constraint which are safe for TypeScript to access.
Type unions work by allowing you to pass any value which satisfies at least one of the type constraints. For example, if we write that a type can be a string OR an array of numbers, any value which is either a string or an array of numbers will be accepted. From the universe of objects perspective, TypeScript will accept any value that satisfies at least one of the constraints provided. From the perspective of safe properties, TypeScript can only ensure that the properties which are common to all types are safe to access. For the same example, a property or method of strings is safe if and only if it is also a property or method of arrays of numbers. If the property or method belongs only to one of the types provided, TypeScript needs more information to determine whether it is safe to allow the access to that property or not.
Type interfaces work by allowing you to pass multiple type constraints which must be simultaneously satisfied by whatever value is passed. For example, if we write that a type has to be of type Student AND TennisPlayer, then the value provided must comply to both the shapes of the Student type and the TennisPlayer type. From the perspective of the universe of objects, TypeScript will accept only the values which satisfy both the constraints. From the perspective of the universe of properties and methods, all the methods of both types are safe to access because we know that whatever provided value will obey to all the type constraints simultaneously.
---------------------------------------
❤️ WHAT YOU SEE? SUPPORT THE PROJECT!
Support me and help this project grow even more!
- Donate via PayPal: https://paypal.me/lauromueller
- Become a Sponsor: / lauromueller
----------------------------------------
This video is part of a TypeScript introductory course for beginners, where I will show you how to the most important concepts of TypeScript and how you can use TypeScript to improve your JavaScript code. I also talk about several best practices and cool things you can do with TypeScript.
- Entire playlist: http://bit.ly/introduction-typescript
- Course exercises: https://www.katacoda.com/lauromueller...
- Video exercises: This video has no specific exercise :(
Some resources for you to dive deeper into TypeScript:
- https://exploringjs.com/tackling-ts/i...
- https://www.typescriptlang.org/docs/h...
Other playlists in my channel:
- Introduction to JavaScript for beginners: http://bit.ly/introduction-javascript
- Building a microservices-based social media application: https://bit.ly/microservices-social-m...
----------------------------------------
LET'S CONNECT?
- Get in touch via LinkedIn: / lauromueller
And of course you don't wanna miss anything from the channel, right? So make sure to subscribe and keep on challenging yourself with the new concepts we discuss in every video :) I have a lot of ideas for playlists, ranging from an introduction to Typescript to a deep dive on more complex topics such as microservices-based systems, securing applications, optimization, and much more!