-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic-5.ts
More file actions
82 lines (64 loc) · 1.68 KB
/
Copy pathbasic-5.ts
File metadata and controls
82 lines (64 loc) · 1.68 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
// Type " Assertion ,Unknown and Never " :
let response : any = "42";
// let numericLength : number = response.length /* here not shows "suggestions"because of "writting this Forcefully." That's why : */
let numericLength : number = (response as string).length
type book ={
name: string
}
let bookString = '{"name":"Who Moved My Cheese"}'
// let bookObject = JSON.parse(bookString)
// console.log(bookObject.);
let bookObject = JSON.parse(bookString) as book
// console.log(bookObject.name);
console.log(bookObject);
const inputElement = document.getElementById("username") as HTMLInputElement
// Number("42") //Please Please don't do this in TS.
let value :any
value = "chai"
value = [1,2,3]
value = 2.5
value.toUpperCase()
let newValue :unknown
newValue = "chai"
newValue = [1,2,3]
newValue = 2.5
// newValue.toUpperCase()
if (typeof newValue === "string") {
newValue.toUpperCase();
}
/*
try {
} catch (error) {
}
*/
/*
try {
} catch (error:any) {
console.log(error.message);
}
*/
try {
} catch (error) {
if (error instanceof Error) {
console.log(error.message);
}
console.log("Error",error);
}
const data:unknown = " Chai pe jay"
const strData:string = data as string
type Role = "admin" | "user" | "superadmin"
function redirectBasedOnRole(role:Role):void {
if (role === "admin ") {
console.log( "Redirecting to admin dashboard");
return
}
if (role === " user ") {
console.log( "Redirecting to user dashboard");
return
}
role;
}
function neverReturn() : never{
while (true) {
}
}