-
Notifications
You must be signed in to change notification settings - Fork 72
/
2_interfaces.ts
77 lines (61 loc) · 1008 Bytes
/
2_interfaces.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
interface Rect {
readonly id: string
color?: string
size: {
width: number
height: number
}
}
const rect1: Rect = {
id: '1234',
size: {
width: 20,
height: 30
},
color: '#ccc'
}
const rect2: Rect = {
id: '12345',
size: {
width: 10,
height: 5
}
}
rect2.color = 'black'
// rect2.id = '3232'
const rect3 = {} as Rect
const rect4 = <Rect>{}
// =====================
interface RectWithArea extends Rect {
getArea: () => number
}
const rect5: RectWithArea = {
id: '123',
size: {
width: 20,
height: 20
},
getArea(): number {
return this.size.width * this.size.height
}
}
// ==================
interface IClock {
time: Date
setTime(date: Date): void
}
class Clock implements IClock {
time: Date = new Date()
setTime(date: Date): void {
this.time = date
}
}
// =================
interface Styles {
[key: string]: string
}
const css: Styles = {
border: '1px solid black',
marginTop: '2px',
borderRadius: '5px'
}