-
Notifications
You must be signed in to change notification settings - Fork 0
/
02_interfaces.ts
72 lines (59 loc) · 1.11 KB
/
02_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
interface Rectangle {
readonly id: string
color?: string
size: {
width: number
height: number
}
}
const rectangle1: Rectangle = {
id: '1',
size: {
width: 20,
height: 30
},
color: '#ccc'
}
const rectangle2: Rectangle = {
id: '2',
size: {
width: 10,
height: 50
}
}
rectangle2.color = 'black'
const rectangle3 = {} as Rectangle
const rectangle4 = <Rectangle>{}
// ==============================
interface RectangleWithArea extends Rectangle {
getArea: () => number
}
const rectangle5: RectangleWithArea = {
id: '3',
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'
}