-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2_interfaces.ts
More file actions
71 lines (60 loc) · 1.02 KB
/
2_interfaces.ts
File metadata and controls
71 lines (60 loc) · 1.02 KB
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
interface Rect {
readonly id: string;
//? unneccesery
color?: string;
size: {
width: number;
height: number;
};
}
const rect1: Rect = {
id: "12232",
size: {
width: 20,
height: 30,
},
color: "#000",
};
const rect2: Rect = {
id: "12233",
size: {
width: 50,
height: 80,
},
};
const rect3 = {} as Rect;
const rect4 = <Rect>{};
//=====================Inheritance
interface RectWithArea extends Rect {
getArea: () => number;
}
const rect5: RectWithArea = {
id: "123",
size: {
width: 200,
height: 300,
},
getArea() {
return this.size.with * 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 grey",
marginTop: "20px",
borderRadius: "5px",
};