-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathindex.ts
102 lines (77 loc) · 1.74 KB
/
index.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
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
// Any, number, string, boolean, object, Array, Tuple, Enum, undefined, null, void, never, unknown
let myName = "Solaiman Shadin";
let age: number;
age = 12;
let isHungry: boolean = false;
type StringOrNumber = number | string;
type direction = 'left' | 'right' | 'top' | 'bottom';
let gameDirection: direction = "right"
let studentId: StringOrNumber = 344304;
studentId = 'web4-344304'
studentId = 122323;
interface Person {
name: string;
age: number;
hobby?: string;
}
type PersonType = { age: number, name: string, hobby: string };
let person: Person = {
name: "Solaiman Shadin",
age: 12,
hobby: "Sleeping"
}
let person2 : Person = {
name: "Someone",
age: 80,
}
// Array
const numbers: (number| string)[] = [33, 40, 50, 80, 'stefjhj'];
const persons: Person[] = [
{
name: "Solaiman Shadin",
age: 12,
hobby: "Sleeping"
},
{
name: "Solaiman Shadin",
age: 12,
hobby: "Sleeping"
},
{
name: "Solaiman Shadin",
age: 12,
hobby: "Sleeping"
}
];
// functions
const greeting = (name: string) : void => {
console.log(`Hello ${name}`)
}
greeting("Shadin")
const add = (a: number, b: number): number => {
return a + b
}
const introduce = ({name, age} : Person) : void => {
console.log(`Hello, my name is ${name}, And I'm ${age}!`)
}
introduce({
name: "Solaiman Shadin",
age: 12,
hobby: "Sleeping"
})
const getArray = <T>(arr: T[]): T[] => {
return arr
}
getArray<string>(['1edrew', 'hjdfhjddfjh dfndj' ]);
getArray<number>([ 1, 2,43, 4 ]);
// enum
enum Week {
Sat = 'SAT',
Sun = "SUN",
Mon = "MON",
Tue = "TUE",
Wed = "WED",
Thr = "THR",
Fri = "FRI"
}
console.log(Week.Sat)