-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic-4.ts
More file actions
112 lines (103 loc) · 2.62 KB
/
Copy pathbasic-4.ts
File metadata and controls
112 lines (103 loc) · 2.62 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
// Type Narrowing and Type Guards :
// Type Narrowing:
function getChai(kind:string | number) {
if (typeof kind === 'string') {
return `Making ${kind} Chai ...`; // ${kind.}
}
return `Chai Oder : ${kind}`; // ${kind.}
// This ${kind} is different between their "dots{.}"
}
function serveChai(msg?: string) {
if (msg) {
return `Serving ${msg} `;
}
// return ` Serving Default Masala Chai ${msg}`;
return ` Serving Default Masala Chai `;
}
function OderChai(size:"small" |'medium' | "large" | number) {
if (size === 'small' ) {
return `small cutting chai...`
}
if (size === "medium" ) {
return `Not enough ,making extra ...`
}
if (size === 'large' ) {
return ` making double extra ...`
}
return `chai order size :- ${size}`
}
class KulhadChai {
serve() {
return ` Serving Kulhad Chai ...`
}
}
class cuttingChai {
serve() {
return ` Serving cutting Chai ...`
}
}
function serve(chai:KulhadChai | cuttingChai) {
if (chai instanceof KulhadChai) {
return chai.serve();
}
/*
if (chai instanceof cuttingChai) {
return chai.serve();
}
*/
}
type ChaiOrder = {
type: string
sugar: number
}
function isChaiOder(obj:any):obj is ChaiOrder {
return (
typeof obj === "object" &&
obj !== null &&
typeof obj.type === "string" &&
typeof obj.type === "number"
)
}
function serveOder(item:ChaiOrder | string) {
if (isChaiOder(item)) {
return ` Serving ${item.type} chai with ${item.sugar}`
}
return ` Serving custom chai: ${item}`
}
type MasalaChai = {type:"masala";spicelevel:number};
type GingerChai = {type:"ginger";amount:number};
type ElaichiChai = {type:"elaichi";aroma:number};
type chai = MasalaChai | GingerChai | ElaichiChai
function MakeChai(oder:chai) {
switch (oder.type) {
case "masala":
return `Masala Chai`
break;
case "ginger":
return `Ginger Chai`
break;
case "elaichi":
return `Elaichi Chai`
break;
default:
break;
}
}
function brew(order:MasalaChai | GingerChai | ElaichiChai) {
if ("spicelevel" in order) {
}
if ("amount" in order) {
}
if ("aroma" in order) {
}
}
/*
function isStringArray(arr:any) : arr is string[]
Or,
*/
function isStringArray(arr:unknown) : arr is string[] // Same
{
return (
Array.isArray(arr) && arr.every(element => typeof element === "number")
);
}