forked from DA0-DA0/dao-dao-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmisc.ts
57 lines (53 loc) · 1.19 KB
/
misc.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
export type ParametersExceptFirst<F> = F extends (
arg0: any,
...rest: infer R
) => any
? R
: never
export type CachedLoadable<T> =
| {
state: 'loading'
contents: undefined
}
| {
state: 'hasValue'
contents: T
updating: boolean
}
| {
state: 'hasError'
contents: Error
}
// These are convenience types that are more useful in UI components. They force
// you to check if data is loading before TypeScript allows you to access the
// data, and they also allow you to check if the data is updating. It is hard to
// use Recoil's loadable types in Storybook stories (to mock components), and
// these types make it much easier. See them used in
// `packages/utils/conversion.ts` and
// `packages/stateless/hooks/useCachedLoadable.ts`.
export type LoadingData<D> =
| {
loading: true
}
| {
loading: false
updating?: boolean
data: D
}
export type LoadingDataWithError<D> =
| {
loading: true
errored: false
}
| {
loading: false
errored: false
updating?: boolean
data: D
}
| {
loading: false
updating?: boolean
errored: true
error: Error
}