-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path01_types.ts
50 lines (40 loc) · 948 Bytes
/
01_types.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
// BOOLEAN
const isFetching: boolean = true
const isLoading: boolean = false
// NUMBER
const int: number = 42
const float: number = 4.2
const num: number = 4e2
// STRING
const message: string = 'hello'
//ARRAY
const stringArray: string[] = ['1', '1', '2', '3', '5', '8', '13']
const numberArray1: number[] = [1, 1, 2, 3, 5, 8, 13]
// or
const numberArray2: Array<number> = [1, 1, 2, 3, 5, 8, 13]
//TUPLE
const contact: [string, number] = ['devandtravel', 1234567]
// ANY
let variable: any = 42
variable = '42'
// FUNCTION
function sayMyName(name: string): void {
console.log(name)
}
sayMyName('devandtravel')
//NEWER
function trowError(message: string): never {
throw new Error(message)
}
// or
function infinite(): never {
while (true) {}
}
// TYPE
type Login = string
const login: Login = 'admin'
type ID = string | number
const id1: ID = 42
const id2: ID = '42'
// NULL, UNDEFINED
type SomeType = string | null | undefined