-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
24 lines (18 loc) · 834 Bytes
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// https://www.youtube.com/watch?v=plsnFfbqVEo
interface ColorVariants {
primary: "blue";
secondary: "red";
tertiary: "green";
}
type PrimaryColor = ColorVariants["primary"]; // type PrimaryColor = "blue"
type NonPrimaryColor = ColorVariants["secondary" | "tertiary"]; // type NonPrimaryColor = "red" | "green"
type EveryColor = ColorVariants[keyof ColorVariants]; // type EveryColor = "blue" | "red" | "green"
type Letters = ["a", "b", "c"];
type AOrB = Letters[0 | 1]; // type AOrB = "a" | "b";
type Letter = Letters[number]; // type Letter = "a" | "b" | "c";
interface UserRoleConfig {
user: ["view", "create", "update"];
superAdmin: ["view", "create", "update", "delete"];
}
// 🤯 this one is crazy
type Role = UserRoleConfig[keyof UserRoleConfig][number]; // type Role = "view" | "create" | "update" | "delete"