-
Notifications
You must be signed in to change notification settings - Fork 72
/
1_types.ts
52 lines (38 loc) · 958 Bytes
/
1_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
51
52
const isFetching: boolean = true
const isLoading: boolean = false
const int: number = 42
const float: number = 4.2
const num: number = 3e10
const message: string = 'Hello Typescript'
const numberArray: number[] = [1, 1, 2, 3, 5, 8, 13]
const numberArray2: Array<number> = [1, 1, 2, 3, 5, 8, 13]
const words: string[] = ['Hello', 'Typescript']
// Tuple
const contact: [string, number] = ['Vladilen', 1234567]
// Any
let variable: any = 42
// ...
variable = 'New String'
variable = []
// ====
function sayMyName(name: string): void {
console.log(name)
}
sayMyName('Хайзенберг')
// Never
function throwError(message: string): never {
throw new Error(message)
}
function infinite(): never {
while (true) {
}
}
// Type
type Login = string
const login: Login = 'admin'
// const login2: Login = 2
type ID = string | number
const id1: ID = 1234
const id2: ID = '1234'
// const id3: ID = true
type SomeType = string | null | undefined