-
Notifications
You must be signed in to change notification settings - Fork 22
/
misc.ts
67 lines (64 loc) · 1.64 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
58
59
60
61
62
63
64
65
66
67
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
}
/**
* Convenience type that is easier to use in UI components. This serves to
* separate the component from the library used to load state/data, preventing
* us from having to use a specific library's types inside of our components.
* This makes it easier to migrate between different data layers and other
* libraries in the future, such as moving from Recoil to React Query.
*
* See this used in `packages/stateful/hooks/useQueryLoadingData.ts`
*/
export type LoadingData<D> =
| {
loading: true
}
| {
loading: false
updating?: boolean
data: D
}
/**
* Convenience type that is easier to use in UI components. This serves to
* separate the component from the library used to load state/data, preventing
* us from having to use a specific library's types inside of our components.
* This makes it easier to migrate between different data layers and other
* libraries in the future, such as moving from Recoil to React Query.
*
* See this used in `packages/stateful/hooks/useQueryLoadingDataWithError.ts`
*/
export type LoadingDataWithError<D> =
| {
loading: true
errored: false
}
| {
loading: false
errored: false
updating?: boolean
data: D
}
| {
loading: false
updating?: boolean
errored: true
error: Error
}