Type Helpers
Utility functions for working with type operations.
Functions
Section titled “Functions”| Function | Description |
|---|---|
Brand |
Brands a base type `T` with a phantom tag `B` to create a nominal type. |
DeepGet |
Resolves the value type at a given `Path` within `T`. |
DeepPartial |
Recursively makes all properties of T optional, including nested objects and array elements. |
DeepSet |
Produces the type of `T` after replacing the value at `Path` with `V`. |
DeepWritable |
Recursively removes `readonly` from all properties of T, including nested objects, array elements, and tuple positions. |
isDirectInstanceOf |
native JS value.constructor === Foo (ES1) |
isFinite / isFiniteNumber |
native JS Number.isFinite(value) (ES2015) |
isHtmlElement / isUrlInstance / isUrlSearchParams |
native JS value instanceof HTMLElement / URL / URLSearchParams (Web API) |
isInfinite |
native JS value === Infinity || value === -Infinity / !Number.isFinite(value) && !Number.isNaN(value) (ES2015) |
isInteger |
native JS Number.isInteger(value) (ES2015) |
isNaN |
native JS Number.isNaN(value) (ES2015) |
isSafeInteger |
native JS Number.isSafeInteger(value) (ES2015) |
isSet (Set data structure) |
native JS value instanceof Set (ES2015) |
isWeakMap / isWeakSet / isWeakRef |
native JS value instanceof WeakMap / WeakSet / WeakRef (ES2015 / ES2021) |
KeysOfType |
Extracts the keys of `T` whose values extend `V`. |
Maybe |
Type for values that can be T, undefined, or null. |
Nullable |
Adds `null` to a type (`T | null`). |
Nullish |
Adds `null` and `undefined` to a type (`T | null | undefined`). |
OmitByValue |
Constructs a type by omitting all entries of `T` whose values extend `V`. |
OptionalKeys |
Extracts the optional keys of an object type `T`. |
PickByValue |
Constructs a type by picking all entries of `T` whose values extend `V`. |
Prettify |
Flattens an intersection type into a single readable object type. |
RequiredKeys |
Extracts the required (non-optional) keys of an object type `T`. |
TypedArrays (isInt8Array, isFloat32Array, ...) |
native JS value instanceof Int8Array / Float32Array / ... (ES2015) |
UnionToIntersection |
Converts a union type to an intersection type: `A | B | C` → `A & B & C`. |
ValueOf |
Produces a union of all value types of an object type `T`. |
