utility-types

Collection of utility types, complementing TypeScript built-in mapped types...

README


utility-types


Collection of utility types, complementing TypeScript built-in mapped types and aliases (think "lodash" for static types).
Latest Stable Version NPM Downloads NPM Downloads Bundlephobia Size
Build Status Dependency Status License Join the community on Spectrum

_Found it useful? Want more updates?_

[Show your support by giving a :star:](https://github.com/piotrwitek/utility-types/stargazers)

Buy Me a Coffee Become a Patron


What's new?


:tada: _Now updated to support TypeScript v3.7_ :tada:




Features


Providing a set of Common Types for TypeScript projects that are idiomatic and complementary to existing TypeScript Mapped Types so you don't need to copy them between the projects.
Providing a set of Additional Types compatible with Flow's Utility Types to allow much easier migration toTypeScript.

Goals


Quality - thoroughly tested for type correctness with type-testing library dts-jest
Secure and minimal - no third-party dependencies
No runtime cost - it's type-level only

Installation


  1. ``` sh
  2. # NPM
  3. npm install utility-types

  4. # YARN
  5. yarn add utility-types
  6. ```

Compatibility Notes


TypeScript support
v3.x.x - TypeScript v3.1+
v2.x.x - TypeScript v2.8.1+
v1.x.x - TypeScript v2.7.2+

Funding Issues

Utility-Types is an open-source project created by people investing their time for the benefit of our community.

Issues like bug fixes or feature requests can be very quickly resolved when funded through the IssueHunt platform.

I highly recommend adding a bounty to the issue that you're waiting for to attract some contributors willing to work on it.
Let's fund issues in this repository

Contributing


We are open for contributions. If you're planning to contribute please make sure to read the contributing guide as it can save you from wasting your time: CONTRIBUTING.md


_(built-in)_ - types built-in TypeScript, no need to import

Table of Contents


Aliases & Type Guards


[Primitive](#primitive)
[isPrimitive](#isprimitive)
[Falsy](#falsy)
[isFalsy](#isfalsy)
[Nullish](#nullish)
[isNullish](#isnullish)

Union operators


* [`SetIntersection`](#setintersectiona-b-same-as-extract)* [`SetDifference`](#setdifferencea-b-same-as-exclude)* [`SetComplement`](#setcomplementa-a1)* [`SymmetricDifference`](#symmetricdifferencea-b)* [`Exclude`](#excludea-b) _(built-in)_* [`Extract`](#extracta-b) _(built-in)_* [`NonNullable`](#nonnullablea) _(built-in)_* [`NonUndefined`](#nonundefineda)

Object operators


* [`FunctionKeys`](#functionkeyst)* [`NonFunctionKeys`](#nonfunctionkeyst)* [`MutableKeys`](#mutablekeyst)* [`ReadonlyKeys`](#readonlykeyst)* [`RequiredKeys`](#requiredkeyst)* [`OptionalKeys`](#optionalkeyst)* [`Optional`](#optionalt-k)* [`Partial`](#partialt) _(built-in)_* [`DeepPartial`](#deeppartialt)* [`Required`](#requiredt-k)* [`DeepRequired`](#deeprequiredt)* [`Readonly`](#readonlyt) _(built-in)_* [`DeepReadonly`](#deepreadonlyt)* [`Mutable`](#mutablet)* [`Pick` _(built-in)_](#pickt-k-built-in)* [`Omit`](#omitt-k) _(built-in)_* [`PickByValue`](#pickbyvaluet-valuetype)* [`PickByValueExact`](#pickbyvalueexactt-valuetype)* [`OmitByValue`](#omitbyvaluet-valuetype)* [`OmitByValueExact`](#omitbyvalueexactt-valuetype)* [`Intersection`](#intersectiont-u)* [`Diff`](#difft-u)* [`Subtract`](#subtractt-t1)* [`Overwrite`](#overwritet-u)* [`Assign`](#assignt-u)* [`ValuesType`](#valuestypet)

Special operators


* [`ReturnType`](#returntypet) _(built-in)_* [`InstanceType`](#instancetypet) _(built-in)_* [`PromiseType`](#promisetypet)* [`Unionize`](#unionizet)* [`Brand`](#brandt-u)* [`UnionToIntersection`](#uniontointersectionu)

Flow's Utility Types


* [`$Keys`](#keyst)* [`$Values`](#valuest)* [`$ReadOnly`](#readonly2)* [`$Diff`](#diff2)* [`$PropertyType`](#propertytypet-k)* [`$ElementType`](#elementtypet-k)* [`$Call`](#callt)* [`$Shape`](#shapet)* [`$NonMaybeType`](#nonmaybetypet)* [`Class`](#classt)
[mixed](#mixed)

Deprecated API (use at own risk)

getReturnOfExpression() - from TS v2.0 it's better to use type-level ReturnType instead


Primitive


Type representing primitive types in JavaScript, and thus TypeScript: string | number | bigint | boolean |  symbol | null | undefined

You can test for singular of these types with [typeof](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/typeof)

isPrimitive


This is a TypeScript Typeguard for the [Primitive](#primitive) type.

This can be useful to control the type of a parameter as the program flows. Example:

  1. ```ts
  2. const consumer = (param: Primitive[] | Primitive): string => {
  3.     if (isPrimitive(param)) {
  4.         // typeof param === Primitive
  5.         return String(param) + ' was Primitive';
  6.     }
  7.     // typeof param === Primitive[]
  8.     const resultArray = param
  9.         .map(consumer)
  10.         .map(rootString => '\n\t' + rootString);
  11.     return resultArray.reduce((comm, newV) => comm + newV, 'this was nested:');
  12. };
  13. ```


Falsy


Type representing falsy values in TypeScript: false | "" | 0 | null | undefined

Except NaN which cannot be represented as a type literal


isFalsy


  1. ```ts
  2. const consumer = (param: Falsy | string): string => {
  3.     if (isFalsy(param)) {
  4.         // typeof param === Falsy
  5.         return String(param) + ' was Falsy';
  6.     }
  7.     // typeof param === string
  8.     return param.toString();
  9. };
  10. ```


Nullish


Type representing nullish values in TypeScript:null | undefined


isNullish


  1. ```ts
  2. const consumer = (param: Nullish | string): string => {
  3.     if (isNullish(param)) {
  4.         // typeof param === Nullish
  5.         return String(param) + ' was Nullish';
  6.     }
  7.     // typeof param === string
  8.     return param.toString();
  9. };
  10. ```


### `SetIntersection` (same as Extract)

Set intersection of given union types A and B

Usage:

  1. ```ts
  2. import { SetIntersection } from 'utility-types';

  3. // Expect: "2" | "3"
  4. type ResultSet = SetIntersection<'1' | '2' | '3', '2' | '3' | '4'>;
  5. // Expect: () => void
  6. type ResultSetMixed = SetIntersection<string | number | (() => void), Function>;
  7. ```


### `SetDifference` (same as Exclude)

Set difference of given union types A and B

Usage:

  1. ```ts
  2. import { SetDifference } from 'utility-types';

  3. // Expect: "1"
  4. type ResultSet = SetDifference<'1' | '2' | '3', '2' | '3' | '4'>;
  5. // Expect: string | number
  6. type ResultSetMixed = SetDifference<string | number | (() => void), Function>;
  7. ```


### `SetComplement`

Set complement of given union types A and (it's subset) A1

Usage:

  1. ```ts
  2. import { SetComplement } from 'utility-types';

  3. // Expect: "1"
  4. type ResultSet = SetComplement<'1' | '2' | '3', '2' | '3'>;
  5. ```


### `SymmetricDifference`

Set difference of union and intersection of given union types A and B

Usage:

  1. ```ts
  2. import { SymmetricDifference } from 'utility-types';

  3. // Expect: "1" | "4"
  4. type ResultSet = SymmetricDifference<'1' | '2' | '3', '2' | '3' | '4'>;
  5. ```


### `NonNullable`

Exclude null and undefined from set A


### `NonUndefined`

Exclude undefined from set A


### `Exclude`

Exclude subset B from set A


### `Extract`

Extract subset B from set A


Operations on objects


### `FunctionKeys`

Get union type of keys that are functions in object type T

Usage:

  1. ```ts
  2. import { FunctionKeys } from 'utility-types';

  3. type MixedProps = { name: string; setName: (name: string) => void };

  4. // Expect: "setName"
  5. type Keys = FunctionKeys<MixedProps>;
  6. ```


### `NonFunctionKeys`

Get union type of keys that are non-functions in object type T

Usage:

  1. ```ts
  2. import { NonFunctionKeys } from 'utility-types';

  3. type MixedProps = { name: string; setName: (name: string) => void };

  4. // Expect: "name"
  5. type Keys = NonFunctionKeys<MixedProps>;
  6. ```


### `MutableKeys`

Get union type of keys that are mutable (not readonly) in object type T

Alias: `WritableKeys`

Usage:

  1. ```ts
  2. import { MutableKeys } from 'utility-types';

  3. type Props = { readonly foo: string; bar: number };

  4. // Expect: "bar"
  5. type Keys = MutableKeys<Props>;
  6. ```


### `ReadonlyKeys`

Get union type of keys that are readonly in object type T

Usage:

  1. ```ts
  2. import { ReadonlyKeys } from 'utility-types';

  3. type Props = { readonly foo: string; bar: number };

  4. // Expect: "foo"
  5. type Keys = ReadonlyKeys<Props>;
  6. ```


### `RequiredKeys`

Get union type of keys that are required in object type T

Usage:

  1. ```ts
  2. import { RequiredKeys } from 'utility-types';

  3. type Props = { req: number; reqUndef: number | undefined; opt?: string; optUndef?: number | undefined; };

  4. // Expect: "req" | "reqUndef"
  5. type Keys = RequiredKeys<Props>;
  6. ```


### `OptionalKeys`

Get union type of keys that are optional in object type T

Usage:

  1. ```ts
  2. import { OptionalKeys } from 'utility-types';

  3. type Props = { req: number; reqUndef: number | undefined; opt?: string; optUndef?: number | undefined; };

  4. // Expect: "opt" | "optUndef"
  5. type Keys = OptionalKeys<Props>;
  6. ```


### `Optional`

From T make a set of properties by key K become optional

Usage:

  1. ```ts
  2. import { Optional } from 'utility-types';

  3. type Props = { name: string; age: number; visible: boolean; };

  4. // Expect: { name?: string; age?: number; visible?: boolean; }
  5. type Props = Optional<Props>
  6. // Expect: { name: string; age?: number; visible?: boolean; }
  7. type Props = Optional<Props, 'age' | 'visible'>;
  8. ```



### `Pick` _(built-in)_

From T pick a set of properties by key K

Usage:

  1. ```ts
  2. type Props = { name: string; age: number; visible: boolean };

  3. // Expect: { age: number; }
  4. type Props = Pick<Props, 'age'>;
  5. ```


### `PickByValue`

From T pick a set of properties by value matching ValueType.
_(Credit: Piotr Lewandowski)_

Usage:

  1. ```ts
  2. import { PickByValue } from 'utility-types';

  3. type Props = { req: number; reqUndef: number | undefined; opt?: string; };

  4. // Expect: { req: number }
  5. type Props = PickByValue<Props, number>;
  6. // Expect: { req: number; reqUndef: number | undefined; }
  7. type Props = PickByValue<Props, number | undefined>;
  8. ```


### `PickByValueExact`

From T pick a set of properties by value matching exact ValueType.

Usage:

  1. ```ts
  2. import { PickByValueExact } from 'utility-types';

  3. type Props = { req: number; reqUndef: number | undefined; opt?: string; };

  4. // Expect: { req: number }
  5. type Props = PickByValueExact<Props, number>;
  6. // Expect: { reqUndef: number | undefined; }
  7. type Props = PickByValueExact<Props, number | undefined>;
  8. ```


### `Omit`

From T remove a set of properties by key K

Usage:

  1. ```ts
  2. import { Omit } from 'utility-types';

  3. type Props = { name: string; age: number; visible: boolean };

  4. // Expect: { name: string; visible: boolean; }
  5. type Props = Omit<Props, 'age'>;
  6. ```


### `OmitByValue`

From T remove a set of properties by value matching ValueType.
_(Credit: Piotr Lewandowski)_

Usage:

  1. ```ts
  2. import { OmitByValue } from 'utility-types';

  3. type Props = { req: number; reqUndef: number | undefined; opt?: string; };

  4. // Expect: { reqUndef: number | undefined; opt?: string; }
  5. type Props = OmitByValue<Props, number>;
  6. // Expect: { opt?: string; }
  7. type Props = OmitByValue<Props, number | undefined>;
  8. ```


### `OmitByValueExact`

From T remove a set of properties by value matching exact ValueType.

Usage:

  1. ```ts
  2. import { OmitByValueExact } from 'utility-types';

  3. type Props = { req: number; reqUndef: number | undefined; opt?: string; };

  4. // Expect: { reqUndef: number | undefined; opt?: string; }
  5. type Props = OmitByValueExact<Props, number>;
  6. // Expect: { req: number; opt?: string }
  7. type Props = OmitByValueExact<Props, number | undefined>;
  8. ```


### `Intersection`

From T pick properties that exist in U

Usage:

  1. ```ts
  2. import { Intersection } from 'utility-types';

  3. type Props = { name: string; age: number; visible: boolean };
  4. type DefaultProps = { age: number };

  5. // Expect: { age: number; }
  6. type DuplicatedProps = Intersection<Props, DefaultProps>;
  7. ```


### `Diff`

From T remove properties that exist in U

Usage:

  1. ```ts
  2. import { Diff } from 'utility-types';

  3. type Props = { name: string; age: number; visible: boolean };
  4. type DefaultProps = { age: number };

  5. // Expect: { name: string; visible: boolean; }
  6. type RequiredProps = Diff<Props, DefaultProps>;
  7. ```


### `Subtract`

From T remove properties that exist in T1 (T1 has a subset of the properties of T)

Usage:

  1. ```ts
  2. import { Subtract } from 'utility-types';

  3. type Props = { name: string; age: number; visible: boolean };
  4. type DefaultProps = { age: number };

  5. // Expect: { name: string; visible: boolean; }
  6. type RequiredProps = Subtract<Props, DefaultProps>;
  7. ```


### `Overwrite`

From U overwrite properties to T

Usage:

  1. ```ts
  2. import { Overwrite } from 'utility-types';

  3. type Props = { name: string; age: number; visible: boolean };
  4. type NewProps = { age: string; other: string };

  5. // Expect: { name: string; age: string; visible: boolean; }
  6. type ReplacedProps = Overwrite<Props, NewProps>;
  7. ```


### `Assign`

From U assign properties to T (just like object assign)

Usage:

  1. ```ts
  2. import { Assign } from 'utility-types';

  3. type Props = { name: string; age: number; visible: boolean };
  4. type NewProps = { age: string; other: string };

  5. // Expect: { name: string; age: string; visible: boolean; other: string; }
  6. type ExtendedProps = Assign<Props, NewProps>;
  7. ```


### `ValuesType`

Get the union type of all the values in an object, tuple, array or array-like type T.

Usage:

  1. ```ts
  2. import { ValuesType } from 'utility-types';

  3. type Props = { name: string; age: number; visible: boolean };
  4. // Expect: string | number | boolean
  5. type PropsValues = ValuesType<Props>;

  6. type NumberArray = number[];
  7. // Expect: number
  8. type NumberItems = ValuesType<NumberArray>;

  9. type ReadonlyNumberTuple = readonly [1, 2];
  10. // Expect: 1 | 2
  11. type AnotherNumberUnion = ValuesType<NumberTuple>;

  12. type BinaryArray = Uint8Array;
  13. // Expect: number
  14. type BinaryItems = ValuesType<BinaryArray>;
  15. ```


### `Partial`

Make all properties of object type optional


### `Required`

From T make a set of properties by key K become required

Usage:

  1. ```ts
  2. import { Required } from 'utility-types';

  3. type Props = { name?: string; age?: number; visible?: boolean; };

  4. // Expect: { name: string; age: number; visible: boolean; }
  5. type Props = Required<Props>
  6. // Expect: { name?: string; age: number; visible: boolean; }
  7. type Props = Required<Props, 'age' | 'visible'>;
  8. ```


### `Readonly`

Make all properties of object type readonly


### `Mutable`

From T make all properties become mutable

Alias: `Writable`

  1. ```ts
  2. import { Mutable } from 'utility-types';

  3. type Props = {
  4.   readonly name: string;
  5.   readonly age: number;
  6.   readonly visible: boolean;
  7. };

  8. // Expect: { name: string; age: number; visible: boolean; }
  9. Mutable<Props>;
  10. ```


### `ReturnType`

Obtain the return type of a function


### `InstanceType`

Obtain the instance type of a class


### `Unionize`

Disjoin object to form union of objects, each with single property

Usage:

  1. ```ts
  2. import { Unionize } from 'utility-types';

  3. type Props = { name: string; age: number; visible: boolean };

  4. // Expect: { name: string; } | { age: number; } | { visible: boolean; }
  5. type UnionizedType = Unionize<Props>;
  6. ```


### `PromiseType`

Obtain Promise resolve type

Usage:

  1. ```ts
  2. import { PromiseType } from 'utility-types';

  3. // Expect: string
  4. type Response = PromiseType<Promise<string>>;
  5. ```


### `DeepReadonly`

Readonly that works for deeply nested structures

Usage:

  1. ```ts
  2. import { DeepReadonly } from 'utility-types';

  3. type NestedProps = {
  4.   first: {
  5.     second: {
  6.       name: string;
  7.     };
  8.   };
  9. };

  10. // Expect: {
  11. //   readonly first: {
  12. //     readonly second: {
  13. //       readonly name: string;
  14. //     };
  15. //   };
  16. // }
  17. type ReadonlyNestedProps = DeepReadonly<NestedProps>;
  18. ```


### `DeepRequired`

Required that works for deeply nested structures

Usage:

  1. ```ts
  2. import { DeepRequired } from 'utility-types';

  3. type NestedProps = {
  4.   first?: {
  5.     second?: {
  6.       name?: string;
  7.     };
  8.   };
  9. };

  10. // Expect: {
  11. //   first: {
  12. //     second: {
  13. //       name: string;
  14. //     };
  15. //   };
  16. // }
  17. type RequiredNestedProps = DeepRequired<NestedProps>;
  18. ```


### `DeepNonNullable`

NonNullable that works for deeply nested structure

Usage:

  1. ```ts
  2. import { DeepNonNullable } from 'utility-types';

  3. type NestedProps = {
  4.   first?: null | {
  5.     second?: null | {
  6.       name?: string | null | undefined;
  7.     };
  8.   };
  9. };

  10. // Expect: {
  11. //   first: {
  12. //     second: {
  13. //       name: string;
  14. //     };
  15. //   };
  16. // }
  17. type RequiredNestedProps = DeepNonNullable<NestedProps>;
  18. ```


### `DeepPartial`

Partial that works for deeply nested structures

Usage:

  1. ```ts
  2. import { DeepPartial } from 'utility-types';

  3. type NestedProps = {
  4.   first: {
  5.     second: {
  6.       name: string;
  7.     };
  8.   };
  9. };

  10. // Expect: {
  11. //   first?: {
  12. //     second?: {
  13. //       name?: string;
  14. //     };
  15. //   };
  16. // }
  17. type PartialNestedProps = DeepPartial<NestedProps>;
  18. ```


### `Brand`

Define nominal type of U based on type of T. Similar to Opaque types in Flow.

Usage:

  1. ```ts
  2. import { Brand } from 'utility-types';

  3. type USD = Brand<number, "USD">
  4. type EUR = Brand<number, "EUR">

  5. const tax = 5 as USD;
  6. const usd = 10 as USD;
  7. const eur = 10 as EUR;

  8. function gross(net: USD): USD {
  9.   return (net + tax) as USD;
  10. }

  11. gross(usd); // ok
  12. gross(eur); // Type '"EUR"' is not assignable to type '"USD"'.
  13. ```


### `UnionToIntersection`

Get intersection type given union type U

Usage:

  1. ```ts
  2. import { UnionToIntersection } from 'utility-types';

  3. // Expect: { name: string } & { age: number } & { visible: boolean }
  4. UnionToIntersection<{ name: string } | { age: number } | { visible: boolean }>
  5. ```



Flow's Utility Types


### `$Keys`

get the union type of all the keys in an object type `T`
https://flow.org/en/docs/types/utilities/#toc-keys

Usage:

  1. ```ts
  2. import { $Keys } from 'utility-types';

  3. type Props = { name: string; age: number; visible: boolean };

  4. // Expect: "name" | "age" | "visible"
  5. type PropsKeys = $Keys<Props>;
  6. ```


### `$Values`

get the union type of all the values in an object type `T`
https://flow.org/en/docs/types/utilities/#toc-values

Usage:

  1. ```ts
  2. import { $Values } from 'utility-types';

  3. type Props = { name: string; age: number; visible: boolean };

  4. // Expect: string | number | boolean
  5. type PropsValues = $Values<Props>;
  6. ```


### `$ReadOnly`

get the read-only version of a given object type `T`
https://flow.org/en/docs/types/utilities/#toc-readonly

Usage:

  1. ```ts
  2. import { $ReadOnly } from 'utility-types';

  3. type Props = { name: string; age: number; visible: boolean };

  4. // Expect: Readonly<{ name: string; age: number; visible: boolean; }>
  5. type ReadOnlyProps = $ReadOnly<Props>;
  6. ```


### `$Diff`

get the set difference of a given object types `T` and `U` (`T \ U`)
https://flow.org/en/docs/types/utilities/#toc-diff

Usage:

  1. ```ts
  2. import { $Diff } from 'utility-types';

  3. type Props = { name: string; age: number; visible: boolean };
  4. type DefaultProps = { age: number };

  5. // Expect: { name: string; visible: boolean; }
  6. type RequiredProps = $Diff<Props, DefaultProps>;
  7. ```


### `$PropertyType`

get the type of property of an object at a given key `K`
https://flow.org/en/docs/types/utilities/#toc-propertytype

Usage:

  1. ```ts
  2. import { $PropertyType } from 'utility-types';

  3. type Props = { name: string; age: number; visible: boolean };
  4. // Expect: string
  5. type NameType = $PropertyType<Props, 'name'>;

  6. type Tuple = [boolean, number];
  7. // Expect: boolean
  8. type A = $PropertyType<Tuple, '0'>;
  9. // Expect: number
  10. type B = $PropertyType<Tuple, '1'>;
  11. ```


### `$ElementType`

get the type of elements inside of array, tuple or object of type `T`, that matches the given index type `K`
https://flow.org/en/docs/types/utilities/#toc-elementtype

Usage:

  1. ```ts
  2. import { $ElementType } from 'utility-types';

  3. type Props = { name: string; age: number; visible: boolean };
  4. // Expect: string
  5. type NameType = $ElementType<Props, 'name'>;

  6. type Tuple = [boolean, number];
  7. // Expect: boolean
  8. type A = $ElementType<Tuple, 0>;
  9. // Expect: number
  10. type B = $ElementType<Tuple, 1>;

  11. type Arr = boolean[];
  12. // Expect: boolean
  13. type ItemsType = $ElementType<Arr, number>;

  14. type Obj = { [key: string]: number };
  15. // Expect: number
  16. type ValuesType = $ElementType<Obj, string>;
  17. ```


### `$Call`

get the return type of a given expression type
https://flow.org/en/docs/types/utilities/#toc-call

The built-in [ReturnType](https://www.typescriptlang.org/docs/handbook/utility-types.html#returntypetype) can be used to accomplish the same goal, although it may have some subtle differences.

Usage:

  1. ```ts
  2. import { $Call } from 'utility-types';

  3. // Common use-case
  4. const add = (amount: number) => ({ type: 'ADD' as 'ADD', payload: amount });
  5. type AddAction = $Call<typeof add>; // { type: 'ADD'; payload: number }

  6. // Examples migrated from Flow docs
  7. type ExtractPropType<T extends { prop: any }> = (arg: T) => T['prop'];
  8. type Obj = { prop: number };
  9. type PropType = $Call<ExtractPropType<Obj>>; // number
  10. // type Nope = $Call>; // Error: argument doesn't match `Obj`.

  11. type ExtractReturnType<T extends () => any> = (arg: T) => ReturnType<T>;
  12. type Fn = () => number;
  13. type FnReturnType = $Call<ExtractReturnType<Fn>>; // number
  14. ```


### `$Shape`

Copies the shape of the type supplied, but marks every field optional.
https://flow.org/en/docs/types/utilities/#toc-shape

Usage:

  1. ```ts
  2. import { $Shape } from 'utility-types';

  3. type Props = { name: string; age: number; visible: boolean };

  4. // Expect: Partial
  5. type PartialProps = $Shape<Props>;
  6. ```


### `$NonMaybeType`

Converts a type `T` to a non-maybe type. In other words, the values of `$NonMaybeType` are the values of `T` except for `null` and `undefined`.
https://flow.org/en/docs/types/utilities/#toc-nonmaybe

Usage:

  1. ```ts
  2. import { $NonMaybeType } from 'utility-types';

  3. type MaybeName = string | null;

  4. // Expect: string
  5. type Name = $NonMaybeType<MaybeName>;
  6. ```


### `Class`

Given a type T representing instances of a class C, the type Class is the type of the class C
https://flow.org/en/docs/types/utilities/#toc-class
\* Differs from original Flow's util - implements only constructor part and won't include any static members. Additionally classes in Typescript are not treated as nominal

Usage:

  1. ```ts
  2. import { Class } from 'utility-types';


  3. function makeStore(storeClass: Class<Store>): Store {
  4.   return new storeClass();
  5. }
  6. ```


mixed


An arbitrary type that could be anything (same as `unknown`)
https://flow.org/en/docs/types/mixed



Related Projects


- [ts-toolbelt](https://github.com/pirix-gh/ts-toolbelt) - Higher type safety for TypeScript
- [$mol_type](https://github.com/eigenmethod/mol/tree/master/type) - Collection of TypeScript meta types for complex logic


License



Copyright (c) 2016 Piotr Witek (http://piotrwitek.github.io)