Should I use type aliases or interfaces? Interfaces or abstract classes? Enums or type aliases? We review the most important characteristics of type aliases, interfaces, classes, enums, and we compare them side-by-side. Watch this episode if you want to know exactly which type keyword to use under certain circumstances.
Contents
00:00 Intro
01:06 Time for a recap
02:26 The Object Notation
Type Aliases
03:59 Intro
04:33 Syntax
04:58 Can't be declared again
06:36 Support for primitive types
08:43 Support for value/literal types
09:59 Where to use a type alias?
10:40 Interfaces - Intro
11:01 Syntax
13:06 Only describe object structures
16:05 Can be extended
17:19 Connect unrelated classes
20:02 Where to use an interface
20:59 Classes - Intro
21:21 Syntax
24:50 Can create objects with OOP keywords
25:37 Available at runtime
29:00 Inheritance
29:38 Abstract classes vs Interfaces
31:00 Enums - Intro
31:20 Syntax
33:44 Can be available at runtime
34:52 Outro
Check out my ✨TypeScript course:
https://tltr-typescript.com
Links I mention in the video
My previous video about type aliases and enums:
• A Complete Guide for Types in TypeScript A...
My previous video about interfaces:
• Master Interfaces in TypeScript
My previous video about classes:
• Master Classes In TypeScript
My blog post with all the coding examples:
https://nicotsou.com/tltr-typescript-...
Errata
Please note that the readonly keyword can be used in both type aliases, interfaces and classes.
This video belongs to my series Too Long To Read TypeScript. Every episode covers in detail a core concept of the language.
You can support this channel by clicking SUBSCRIBE :)