A union type in TypeScript allows you to declare a value that can have different types.
My FREE programming apps:
https://apps.apple.com/app/id659282498
https://play.google.com/store/apps/de...
My FREE TypeScript Course:
https://typescript.tv/
Timeline:
00:08 - What is a union type?
00:51 - A union in set theory
01:30 - Creating a type alias
02:11 - Benefits of type aliases
02:24 - Common mistakes with unions
03:16 - Union types in index signatures
04:40 - Discriminated Unions (Tagged Unions)
08:08 - Union types and interfaces
Resources:
➜ Unions & Intersections: https://www.typescriptlang.org/docs/h...
➜ Venn diagram: https://en.wikipedia.org/wiki/Venn_di...
➜ Type aliases: https://www.typescriptlang.org/docs/h...
➜ Discriminated Unions: https://basarat.gitbook.io/typescript...
Follow TypeScript TV:
🌐 https://typescript.tv
🐦 / typescripttv
📺 / typescripttv
Hashtags:
#TypeScript #JavaScript #LearnToCode