-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathundertand-keywords-in-typescript.ts
93 lines (63 loc) · 1.38 KB
/
undertand-keywords-in-typescript.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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
//! explain easy typescript keywords like exntends, implements, readonly, private, public, protected, static, keyof , typeof, in ,
//* 1. extends / example
class Parent {
// ...
}
class Child extends Parent {
// ...
}
//* 2. implements / example
interface IParent {
// ...
}
class ParentImpl implements IParent {
// ...
}
//* 3. readonly / example
class ParentReadOnly {
public readonly name: string;
constructor(name: string) {
this.name = name;
}
}
//* 4. private / example
class ParentPrivate {
private name: string;
constructor(name: string) {
this.name = name;
}
}
//* 5. public / example
class ParentPublic {
public name: string;
constructor(name: string) {
this.name = name;
}
}
//* 6. protected / example
class ParentProtected {
protected name: string;
constructor(name: string) {
this.name = name;
}
}
//* 7. static / example
class ParentStatic {
//@ts-ignore
static name: string;
constructor(name: string) {
ParentStatic.name = name;
}
}
//* 8. keyof / example
interface IParentKeyOf {
name: string;
age: number;
}
type ParentKeyOf = keyof IParentKeyOf; // 'name' | 'age'
const nom: ParentKeyOf = 'name';
//* 9. typeof / example
const nom2: typeof nom = 'name';
//* 10. in / example
type ParentIn = 'name' | 'age';
const nom3: ParentIn = 'name';