@terascope/types / utility
utility
Index
Interfaces
Interface | Description |
---|---|
AnyObject | A simple object with any values |
EmptyObject | - |
ListOfRecursiveArraysOrValues | A simple definitions of array |
Many | A simple definitions of array |
RecursiveArray | A simple definitions of array |
Type Aliases
Diff<T, U>
Diff<
T
,U
>:T
extendsU
?never
:T
Remove types from T that are assignable to U
Type parameters
Type parameter |
---|
T |
U |
Source
Filter<T, U>
Filter<
T
,U
>:T
extendsU
?T
:never
Remove types from T that are NOT assignable to U
Type parameters
Type parameter |
---|
T |
U |
Source
FilteredResult<T, I, E>
FilteredResult<
T
,I
,E
>:{ [P in keyof T]: P extends I ? T[P] : P extends E ? never : T[P] }
Filters the keys of an object (T), by list of included keys (I) and excluded (E)
Type parameters
Type parameter |
---|
T |
I extends keyof T |
E extends keyof T |
Source
Maybe<T>
Maybe<
T
>:T
|Nil
Type parameters
Type parameter |
---|
T |
Source
Nil
Nil:
null
|undefined
Source
Omit<T, K>
Omit<
T
,K
>:Pick
<T
,Exclude
<keyofT
,K
>>
Omit the properties available to type. Useful for excluding properties from a type
Example
`Omit<{ a: number, b: number, c: number }, 'b'|'c'> // => { a: 1 }`
Type parameters
Type parameter |
---|
T |
K extends keyof T |
Source
Optional<T, K>
Optional<
T
,K
>: { [P in keyof T]: P extends K ? NonNullable<T[P]> | undefined : NonNullable<T[P]> }
Like Partial but makes certain properties optional
Example
`Optional<{ a: number, b: number }, 'b'>`
Type parameters
Type parameter |
---|
T |
K extends keyof T |
Source
Override<T1, T2>
Override<
T1
,T2
>:{ [P in keyof T1]: P extends keyof T1 ? T2[P] : T1[P] }
Override specific properties on a type
Example
`Override<{ a: number, b: number }, { b: string }>`
Type parameters
Type parameter |
---|
T1 |
T2 extends { [P in keyof T2]: P extends keyof T1 ? T2[P] : never } |
Source
Overwrite<T1, T2>
Overwrite<
T1
,T2
>:{ [P in Exclude<keyof T1, keyof T2>]: T1[P] }
&T2
Overwrite a simple type with different properties. Useful changing and adding additional properties
Example
`Overwrite<{ a: number, b: number }, { b?: number }>`
Type parameters
Type parameter |
---|
T1 |
T2 |
Source
PartialDeep<T>
PartialDeep<
T
>:{ [P in keyof T]?: PartialDeep<T[P]> }
A deep partial object
Type parameters
Type parameter |
---|
T |
Source
Required<T, K>
Required<
T
,K
>: { [P in keyof T]: P extends K ? NonNullable<T[P]> : NonNullable<T[P]> | undefined }
Like Partial but makes certain properties required
Example
`Required<{ a: number, b: number }, 'b'>`
Type parameters
Type parameter |
---|
T |
K extends keyof T |
Source
Unpacked<T>
Unpacked<
T
>:T
extends infer U[] ?U
:T
extends (...args
) => infer U ?U
:T
extendsPromise
<infer U> ?U
:T
From https://www.typescriptlang.org/docs/handbook/advanced-types.html#type-inference-in-conditional-types
Type parameters
Type parameter |
---|
T |
Source
Unwrapped<T>
Unwrapped<
T
>:NonNullable
<T
>
Type parameters
Type parameter |
---|
T |
Source
ValueOf<T>
ValueOf<
T
>:T
[keyofT
]
Get the types object (the opposite of keyof)
Type parameters
Type parameter |
---|
T |
Source
WithoutNil<T>
WithoutNil<
T
>:{ [P in keyof T]: T[P] extends Nil ? never : T[P] }
Without null or undefined properties
Type parameters
Type parameter |
---|
T |