-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstatus.ts
69 lines (59 loc) · 1.71 KB
/
status.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
/* eslint-disable prettier/prettier */
/* eslint-disable no-unused-vars */
// not good way
const REQUEST_STATUS = {
status_idle: "IDLE",
status_pending: "PENDING",
status_success: "SUCCESS",
status_error: "ERROR",
};
// eslint-disable-next-line no-unused-vars
type TTest1 = typeof REQUEST_STATUS;
/*
type TTest1 = {
status_idle: string;
status_pending: string;
status_success: string;
status_error: string;
}
*/
type TTest2 = keyof typeof REQUEST_STATUS;
// type TTest2 = "status_idle" | "status_pending" | "status_success" | "status_error"
type TTest3 = (typeof REQUEST_STATUS)[keyof typeof REQUEST_STATUS];
// type TTest3 = string
// better way
/* eslint-disable prettier/prettier */
/* eslint-disable no-unused-vars */
const REQUEST_STATUS2 = {
status_idle: "IDLE",
status_pending: "PENDING",
status_success: "SUCCESS",
status_error: "ERROR",
} as const;
// in "as const" add readonly to all status
/*
const REQUEST_STATUS2: {
readonly status_idle: "IDLE";
readonly status_pending: "PENDING";
readonly status_success: "SUCCESS";
readonly status_error: "ERROR";
}
*/
// eslint-disable-next-line no-unused-vars
type TTest11 = typeof REQUEST_STATUS2;
/*
type TTest1 = {
readonly status_idle: string;
readonly status_pending: string;
readonly status_success: string;
readonly status_error: string;
}
*/
type TTest22 = keyof typeof REQUEST_STATUS2;
// type TTest2 = "status_idle" | "status_pending" | "status_success" | "status_error"
type TTest33 = (typeof REQUEST_STATUS2)[keyof typeof REQUEST_STATUS2];
// type TTest33 = "IDLE" | "PENDING" | "SUCCESS" | "ERROR"
// User.tsx
const [networkState, setNetworkState] = useState<REQUEST_TYPES>(
REQUEST_STATUS.idle
);