Files
javascript-packages/packages/typescript-types

Typescript Types

A utility types library for Typescript.

Types

The types included in this library are categorized by their purpose.

Definition Types

Type Description
Primitive A union of the primitive types of TypeScript.
BuiltIns A union of the built-in types of TypeScript.
NonContainerType A union of types, whose primary pourpose is not holding other types.

Test Types

Type Description
IsAny<T> true if T is any, false otherwise (null, undefined also yield false)
IsNever<T> true if T is never, false otherwise (null, undefined, any also yield false)
IsUndefined<T> true if T is undefined, false otherwise (null, never, any also yield false).
IsUnknown<T> true if T is unknown, false otherwise (null, never, any also yield false).
If<Test, TrueBranch, FalseBranch> Returns TrueBranch if Test is true, FalseBranch otherwise1 .
IsKeyOf<T, K> true if K is a key of T, false otherwise. If T is any, any K but never will yield true.
IsEmptyString<S> true if S is the empty string '', false otherwise.2

Extraction Types

Type Description
KeyPaths<T, O, F> A union of all keypaths of T where the value does not extend F. Separator can be set via O['separator'].
OptionalKeysOf<T> A union of all keys of T that are marked as optional. If T is a union, a union of the optional keys of all union members of T is returned3 .
PickAssignable<T, K> Return a mapped type with all keys of T that extend K. If no key does extend K an empty type is returned.

Conversion Types

Type Description
KeyPath<T, Separator = '.'> Converts a Separator separated string into a tuple of its parts.
Simplify<T, E, I> Maps types that extend I and not E to their properties. Helps diagnostic messages to be clearer.

Combination Types

Type Description
Assign<Shape, Defaults, Obj> Return a type with the structure of Shape and value types from Obj or Default for missing optional keys in Obj.

  1. If boolean is passed as Test the return value is a union of both branches, i.e. TrueBranch | FalseBranch. ↩︎

  2. If T is any will yield true, as it is taken to be any string. ↩︎

  3. If T is any, it returns a union of string and number 'string | number'. ↩︎