-
Notifications
You must be signed in to change notification settings - Fork 0
Unions
To understand what are unions and how they work, lets assume a single scenarion in which we are creating a user, with an access role. If we wish to strict this access role to be either guest, member or admin, this can be done easily with unions types - a combination of literal types - in TypeScript.
The snippet of code below exemplifies how this could be achieved.
type UserRole = 'guest' | 'member' | 'admin';
let userRole: UserRole = 'guest';Those notes were written while watching the tutorial videos while taking the classes from the online course Learn TypeScript on Scrimba.
Because english is not my mother language, they can contain some typos and everything written here is based on my understanding about the discussed topics and may not be 100% accurate.
If you want the full course, support the instructor by buying their course on Scrimba.
- Home
- Introduction
- Introduction to TypeScript
- The Pizza Application
- Move to TypeScript
- Defensive Coding
- Typing variables
- Typing Pizza App: part 1
- Custom types
- Typing Pizza App: part 2
- Nested Object types
- Optional Properties
- Typing Pizza App: part 3
- Array Types
- Typing Pizza App: part 4
- Literal Types
- Unions
- Typing Pizza App: part 5
- Typing Pizza App: part 6
- Typing Pizza App: part 7
- Returning Types
- Typing Pizza App: part 8
- Any Type
- Typing Pizza App: part 9
- Utility Types
- Typing Pizza App: part 10
- Generics
- Typing Pizza App: part 11