Skip to content

Type Helpers

Utility functions for working with type operations.

FunctionDescription
BrandBrands a base type T with a phantom tag B to create a nominal type.
DeepGetResolves the value type at a given Path within T.
DeepPartialRecursively makes all properties of T optional, including nested objects and array elements.
DeepSetProduces the type of T after replacing the value at Path with V.
DeepWritableRecursively removes readonly from all properties of T, including nested objects, array elements, and tuple positions.
isDirectInstanceOfnative JS value.constructor === Foo (ES1)
isFinite / isFiniteNumbernative JS Number.isFinite(value) (ES2015)
isHtmlElement / isUrlInstance / isUrlSearchParamsnative JS value instanceof HTMLElement / URL / URLSearchParams (Web API)
isInfinitenative JS value === Infinity || value === -Infinity / !Number.isFinite(value) && !Number.isNaN(value) (ES2015)
isIntegernative JS Number.isInteger(value) (ES2015)
isNaNnative JS Number.isNaN(value) (ES2015)
isSafeIntegernative JS Number.isSafeInteger(value) (ES2015)
isSet (Set data structure)native JS value instanceof Set (ES2015)
isWeakMap / isWeakSet / isWeakRefnative JS value instanceof WeakMap / WeakSet / WeakRef (ES2015 / ES2021)
KeysOfTypeExtracts the keys of T whose values extend V.
MaybeType for values that can be T, undefined, or null.
NullableAdds null to a type (T | null).
NullishAdds null and undefined to a type (T | null | undefined).
OmitByValueConstructs a type by omitting all entries of T whose values extend V.
OptionalKeysExtracts the optional keys of an object type T.
PickByValueConstructs a type by picking all entries of T whose values extend V.
PrettifyFlattens an intersection type into a single readable object type.
RequiredKeysExtracts the required (non-optional) keys of an object type T.
TypedArrays (isInt8Array, isFloat32Array, ...)native JS value instanceof Int8Array / Float32Array / ... (ES2015)
UnionToIntersectionConverts a union type to an intersection type: A | B | CA & B & C.
ValueOfProduces a union of all value types of an object type T.