forked from alloc/types
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.d.ts
89 lines (68 loc) · 2.33 KB
/
index.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
/** Try to simplify `&` out of an object type */
export type Remap<T> = {} & {
[P in keyof T]: T[P]
}
export type Pick<T, K extends keyof T> = {} & {
[P in K]: T[P]
}
export type Omit<T, K> = Pick<T, Exclude<keyof T, K>>
export type Partial<T> = {} & {
[P in keyof T]?: T[P] | undefined
}
export type Overwrite<T, U> = Remap<Omit<T, keyof U> & U>
export type MergeUnknown<T, U> = Remap<T & Omit<U, keyof T>>
export type MergeDefaults<T extends object, U extends Partial<T>> = Remap<
Omit<T, keyof U> & Partial<Pick<T, Extract<keyof U, keyof T>>>
>
export type OneOrMore<T> = T | readonly T[]
export type Falsy = false | null | undefined
// https://github.com/microsoft/TypeScript/issues/14829#issuecomment-504042546
export type NoInfer<T> = [T][T extends any ? 0 : never]
export type StaticProps<T> = Omit<T, keyof T & 'prototype'>
export interface Lookup<T = any> {
[key: string]: T
}
/** Intersected with other object types to allow for unknown properties */
export interface UnknownProps extends Lookup<unknown> {}
/** Use `[T] extends [Any]` to know if a type parameter is `any` */
export class Any {
private _: never
}
export type AnyFn<In extends ReadonlyArray<any> = any[], Out = any> = (
...args: In
) => Out
/** Ensure the given type is an object type */
export type ObjectType<T> = T extends object ? T : {}
/** Get the keys of each object type in a given union */
export type AllKeys<T> = T extends any ? keyof T : never
/** Merge all object types in a given union. Property types are unioned. */
export type CombineObjects<T> = [AllKeys<T>] extends [infer U]
? { [P in U & string]: CombineProp<T, P> }
: never
/**
* Given a union of object types, find which ones contain the given
* property and merge their types with a union.
*/
export type CombineProp<T, P extends string> = T extends any
? P extends keyof T
? T[P]
: never
: never
/** Convert a union to an intersection */
export type Intersect<U> = (U extends any
? (k: U) => void
: never) extends (k: infer I) => void
? I
: never
export type Exclusive<T> = keyof T extends infer Keys
? Keys extends infer Key
? Remap<
{ [P in Extract<keyof T, Key>]: T[P] } &
{ [P in Exclude<keyof T, Key>]?: undefined }
>
: never
: never
/** An object that needs to be manually disposed of */
export interface Disposable {
dispose(): void
}