-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshort_videos.ts
104 lines (73 loc) · 2.25 KB
/
short_videos.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
103
104
export const StatusArray = [
'NOT_STARTED',
'ACTIVE',
'COMPLETED',
'SUBMITTING',
'VIEWING_ANSWERS'
] as const;
export type Status = typeof StatusArray[number];
// "NOT_STARTED" | "ACTIVE" | "COMPLETED" | "SUBMITTING" | "VIEWING_ANSWERS"
// ========================================================================================
type map1 = {
[key: string]: string
}
type map2 = Record<string, string>
const map3 = new Map<string, string>()
// ========================================================================================
interface IPerson {
address?: {
city?: string
}
}
const person: IPerson = {}
const city1 = person.address.city // error
const city2 = person.address?.city // ? optional chaining
const city3 = person.address!.city // ! undefined chaining
// ========================================================================================
interface IPerson {
name: string,
age: number
}
// mapped type custom partial-type
type IPartialPerson<T> = {
[P in keyof T]?: T[P] | undefined
}
type IRecordPerson<K extends string | number, T> = {
[P in K]: T
}
const person2: Partial<IPerson> | Record<string, string | number> = {}
const person3: IPartialPerson<IPerson> | IRecordPerson<string, IPerson> = {}
// ========================================================================================
const article = {
title: 'elem.js',
id: 23,
author: 'messi'
}
type ArticleType = typeof article
// {
// title: string,
// id: number,
// author: string
// }
type ArticleKeys = keyof ArticleType
// "title" | "id" | "author"
// ========================================================================================
const getData1 = (): Promise<JSON> => {
return fetch("api/data").then(res => res.json())
}
const getData2 = (): Promise<any> => {
return fetch("api/data").then(res => res.json())
}
interface User {
id: number;
firstName: string;
}
// @ts-ignore
axios.get<User[]>('http://localhost:8080/admin/users')
.then(response => {
console.log(response.data);
// @ts-ignore
setUserList(response.data);
});
// ========================================================================================
// ========================================================================================