-
Notifications
You must be signed in to change notification settings - Fork 1
/
declaration.d.ts
162 lines (147 loc) · 5.17 KB
/
declaration.d.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/// <reference types="vite/client" />
// declare module '@department-of-veterans-affairs/react-components' {
// declare class TextInput extends React.Component<any, any, any> {
// constructor()
// handleChange(domEvent: any): void
// handleBlur(): void
// UNSAFE_componentWillMount(): void
// inputId: string
// componentDidMount(): void
// componentWillUnmount(): void
// render(): import('react/jsx-runtime').JSX.Element
// }
// declare namespace TextInput {
// namespace propTypes {
// let errorMessage: PropTypes.Requireable<string>
// let label: PropTypes.Validator<any>
// let placeholder: PropTypes.Requireable<string>
// let name: PropTypes.Requireable<string>
// let autocomplete: PropTypes.Requireable<string>
// let required: PropTypes.Requireable<boolean>
// let field: PropTypes.Validator<
// NonNullable<
// PropTypes.InferProps<{
// value: PropTypes.Requireable<string>
// dirty: PropTypes.Requireable<boolean>
// }>
// >
// >
// let additionalClass: PropTypes.Requireable<string>
// let charMax: PropTypes.Requireable<number>
// let onValueChange: PropTypes.Validator<(...args: any[]) => any>
// let ariaDescribedBy: PropTypes.Requireable<string>
// let type: PropTypes.Requireable<string>
// let tabIndex: PropTypes.Requireable<number>
// let enableAnalytics: PropTypes.Requireable<boolean>
// }
// namespace defaultProps {
// let type_1: string
// export { type_1 as type }
// }
// }
// }
/**
* Global type declarations for the app.
*/
// Image module declarations
declare module '*.png'
declare module '*.svg'
// Style module declaration
declare module '*.css' {
const classes: { [key: string]: string }
export default classes
}
/**
* Utility type that sets chosen attributes of type T as required. It makes use
* of T for the original type, and K as a union of T keys that need to be set
* as required. The expression { [_ in K]: {} } represents a mapped type where
* every property K in T is defined as necessary. This type is beneficial for
* setting specific properties of object type T as non-nullable or needed.
*/
type WithRequired<T, K extends keyof T> = T & { [_ in K]: NonNullable<T[_]> }
/**
* Generalizable way to require at least one of a set of properties is provided.
* @see https://stackoverflow.com/a/49725198/1526037
* @author KPD (https://stackoverflow.com/users/2077574/kpd)
*/
type RequireAtLeastOne<T, Keys extends keyof T = keyof T> = Pick<
T,
Exclude<keyof T, Keys>
> &
{
[K in Keys]-?: Required<Pick<T, K>> & Partial<Pick<T, Exclude<Keys, K>>>
}[Keys]
/**
* Partial but not absolute way to require that one and only one is provided.
* @see https://stackoverflow.com/a/49725198/1526037
* @author KPD (https://stackoverflow.com/users/2077574/kpd)
*/
type RequireOnlyOne<T, Keys extends keyof T = keyof T> = Pick<
T,
Exclude<keyof T, Keys>
> &
{
[K in Keys]-?: Required<Pick<T, K>> &
Partial<Record<Exclude<Keys, K>, undefined>>
}[Keys]
/**
* Utility type that takes two types T and U. It creates a new type that has
* all the properties of T, and where the properties that share with U are
* marked as never. This makes sure that the intersection of properties
* between T and U is not present in the final type.
*/
type Only<T, U> = {
[P in keyof T]: T[P]
} & {
[P in keyof U]?: never
}
/**
* Utility type that is a union type of Only<T, U> and Only<U, T>.
* It represents a type that contains properties of either T or U,
* but not the properties that are shared by T and U.
* This is useful when you want to specify a type that takes
* either one or the other type, but not a mix of both.
*/
type Either<T, U> = Only<T, U> | Only<U, T>
/**
* Generic Error Callback type
*/
type ErrorCallbackType = (err: Error) => void
/**
* Date Interface
*/
interface Date {
/**
* Give a more precise return type to the method `toISOString()`:
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString
*/
toISOString(): TDateISO
}
type TYear = `${number}${number}${number}${number}`
type TMonth = `${number}${number}`
type TDay = `${number}${number}`
type THours = `${number}${number}`
type TMinutes = `${number}${number}`
type TSeconds = `${number}${number}`
type TMilliseconds = `${number}${number}${number}`
/**
* Represent a string like `2021-01-08`
*/
type TDateISODate = `${TYear}-${TMonth}-${TDay}`
/**
* Represent a string like `14:42:34.678`
*/
type TDateISOTime = `${THours}:${TMinutes}:${TSeconds}.${TMilliseconds}`
/**
* Represent a string like `2021-01-08T14:42:34.678Z` (format: ISO 8601).
*
* It is not possible to type more precisely (list every possible values
* for months, hours, etc.) as it would result in a warning from TypeScript:
* "Expression produces a union type that is too complex to represent. ts(2590)
*/
type TDateISO = `${TDateISODate}T${TDateISOTime}Z`
/**
* Represent a string like `2021-01-08T14:42:34.678` (format: ISO 8601).
* The server needs the string to be formatted this way.
*/
type TDateISOWithoutZ = `${TDateISODate}T${TDateISOTime}`