-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathTypeScript.html
More file actions
75 lines (67 loc) · 2.08 KB
/
Copy pathTypeScript.html
File metadata and controls
75 lines (67 loc) · 2.08 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
72
73
74
75
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
<div>
<h3>
Intersection Types
</h3>
<ul>
<li>combinations of two or more types, which are really useful for objects and parameters that must be implemented in more than one interface.</li>
</ul>
<p>
interface Animal {
kind: string;
}
interface Person {
firstName: string;
lastName: string;
age: number;
}
interface Employee {
employeeCode: string;
}
<b>let employee: Animal & Person & Employee = {</b>
kind: 'human',
firstName: 'Jane',
lastName: 'Smith',
age: 20,
employeeCode: '123'
}
</p>
<b> employee object has all the properties of Animal , Person , and Employee </b>
</div>
<div>
<h3>
Union Types
</h3>
<ul>
<li>Create a new type that lets us create objects that have some/all of the properties of each type</li>
</ul>
<p>
interface Animal {
kind: string;
}
interface Person {
firstName: string;
lastName: string;
age: number;
}
interface Employee {
employeeCode: string;
}
<b>let employee: Animal | Person | Employee = {</b>
kind: 'human',
firstName: 'Jane',
lastName: 'Smith',
age: 20
}
</p>
<b> employee object of the Animal | Person | Employee type which means that it can have some of the properties of the Animal, Person, or Employee interfaces.</b>
<b>Not all of them have to be included, but if they’re included, then the type has to match the ones in the interface</b>
</div>
</body>
</html>