ts-toolbelt

  • Version 9.6.0
  • Published
  • 248 kB
  • No dependencies
  • Apache-2.0 license

Install

npm i ts-toolbelt
yarn add ts-toolbelt
pnpm add ts-toolbelt

Overview

TypeScript's largest utility library

Index

Namespaces

Namespaces

namespace A

module 'out/Any/_api.d.ts' {}

type At

type At<A extends any, K extends Key> = A extends List
? number extends A['length']
? K extends number | `${number}`
? A[never] | undefined
: undefined
: K extends keyof A
? A[K]
: undefined
: unknown extends A
? unknown
: K extends keyof A
? A[K]
: undefined;
  • Get in O the type of a field of key K

    Parameter O

    to extract from

    Parameter K

    to extract at

    Returns

    [[Any]]

    Example 1

    import {O} from 'ts-toolbelt'
    type User = {
    info: {
    name: string
    age: number
    payment: {}
    }
    id: number
    }
    type test0 = O.At<User, 'id'> // number

type Await

type Await<P extends any> = P extends Promise<infer A> ? A : P;
  • Get the result type of a Promise

    Parameter P

    A promise

    Returns

    [[Any]]

    Example 1

    import {C} from 'ts-toolbelt'
    const promise = new Promise<string>((res, rej) => res('x'))
    type test0 = C.Await<typeof promise> // string
    type test1 = C.Await<Promise<number>> // number

type Cast

type Cast<A1 extends any, A2 extends any> = A1 extends A2 ? A1 : A2;
  • Ask TS to re-check that A1 extends A2. And if it fails, A2 will be enforced anyway. Can also be used to add constraints on parameters.

    Parameter A1

    to check against

    Parameter A2

    to cast to

    Returns

    A1 | A2

    Example 1

    import {A} from 'ts-toolbelt'
    type test0 = A.Cast<'42', string> // '42'
    type test1 = A.Cast<'42', number> // number

type Compute

type Compute<A extends any, depth extends Depth = 'deep'> = {
flat: ComputeFlat<A>;
deep: ComputeDeep<A>;
}[depth];
  • Force TS to load a type that has not been computed (to resolve composed types that TS haven't fully resolved, for display purposes mostly).

    Parameter A

    to compute

    Returns

    A

    Example 1

    import {A} from 'ts-toolbelt'
    type test0 = A.Compute<{x: 'x'} & {y: 'y'}> // {x: 'x', y: 'y'}

type Contains

type Contains<A1 extends any, A2 extends any> = Extends<A1, A2> extends 1 ? 1 : 0;
  • Check whether A1 is part of A2 or not. It works like [[Extends]] but [[Boolean]] results are narrowed to [[False]].

    Parameter A1

    Parameter A2

    Returns

    [[Boolean]]

    Example 1

    type test0 = A.Contains<'a' | 'b', 'b'> // False
    type test1 = A.Contains<'a', 'a' | 'b'> // True
    type test2 = A.Contains<{a: string}, {a: string, b: number}> // False
    type test3 = A.Contains<{a: string, b: number}, {a: string}> // True
    type test4 = A.Contains<never, never> // False
    /// Nothing cannot contain nothing, use `A.Equals`

type Equals

type Equals<A1 extends any, A2 extends any> = (<A>() => A extends A2
? 1
: 0) extends <A>() => A extends A1 ? 1 : 0
? 1
: 0;
  • Check whether A1 is equal to A2 or not.

    Parameter A1

    Parameter A2

    Returns

    [[Boolean]]

    Example 1

    import {A} from 'ts-toolbelt'
    type test0 = A.Equals<42 | 0, 42 | 0> // true
    type test1 = A.Equals<{a: string}, {b: string}> // false
    type test3 = A.Equals<{a: string}, {readonly a: string}> // false

type Extends

type Extends<A1 extends any, A2 extends any> = [A1] extends [never]
? 0
: A1 extends A2
? 1
: 0;
  • Check whether A1 is part of A2 or not. The difference with extends is that it forces a [[Boolean]] return.

    Parameter A1

    Parameter A2

    Returns

    [[Boolean]]

    Example 1

    import {A} from 'ts-toolbelt'
    type test0 = A.Extends<'a' | 'b', 'b'> // Boolean
    type test1 = A.Extends<'a', 'a' | 'b'> // True
    type test2 = A.Extends<{a: string}, {a: any}> // True
    type test3 = A.Extends<{a: any}, {a: any, b: any}> // False
    type test4 = A.Extends<never, never> // False
    /// Nothing cannot extend nothing, use `A.Equals`

type Is

type Is<A extends any, A1 extends any, match extends Match = 'default'> = {
default: Extends<A, A1>;
'contains->': Contains<A, A1>;
'extends->': Extends<A, A1>;
'<-contains': Contains<A1, A>;
'<-extends': Extends<A1, A>;
equals: Equals<A1, A>;
}[match];
  • Check whether A is similar to A1 or not. In other words, it is a compact type that bundles [[Equals]], [[Extends]], [[Contains]], comparison types.

    Parameter A

    to be compared

    Parameter A1

    to compare to

    Parameter match

    (?='default') to change precision

    Returns

    [[Boolean]]

    Example 1

    import {A} from 'ts-toolbelt'
    type test0 = A.Is<'a', 'a' | 'b', 'extends->'> // True
    type test1 = A.Is<'a' | 'b', 'a', 'extends->'> // Boolean
    type test2 = A.Is<'a', 'a' | 'b', '<-extends'> // Boolean
    type test3 = A.Is<'a' | 'b', 'a', '<-extends'> // True
    type test4 = A.Is<'a', 'a' | 'b', 'contains->'> // True
    type test5 = A.Is<'a' | 'b', 'a', 'contains->'> // False
    type test6 = A.Is<'a', 'a' | 'b', '<-contains'> // False
    type test7 = A.Is<'a' | 'b', 'a', '<-contains'> // True
    type test8 = A.Is<'a', 'a' | 'b', 'equals'> // False
    type test9 = A.Is<'b' |'a', 'a' | 'b', 'equals'> // True

type Key

type Key = string | number | symbol;
  • Describes index keys for any type

type Keys

type Keys<A extends any> = A extends List
? Exclude<keyof A, keyof any[]> | number
: keyof A;
  • Get the keys of A

    Parameter A

    Returns

    [[Key]]

    Example 1

    ```ts ```

type KnownKeys

type KnownKeys<O extends object> = {
[K in keyof O]: string extends K ? never : number extends K ? never : K;
} extends {
[K in keyof O]: infer U;
}
? U & Keys<O>
: never;
  • Get the known keys of an [[Object]]

    Parameter O

    Returns

    [[Key]]

    Example 1

    ```ts ```

type Promise

type Promise<A extends any> = globalThis.Promise<
A extends globalThis.Promise<infer X> ? X : A
>;
  • Create an asynchronous operation like the original Promise type but this one prevents promises to be wrapped within more promises (not possible).

    Parameter A

    Example 1

    import {A} from 'ts-toolbelt'
    type test0 = A.Promise<Promise<number>> // Promise<number>
    type test1 = Promise<Promise<number>> // Promise<Promise<number>>

type Try

type Try<A1 extends any, A2 extends any, Catch = never> = A1 extends A2 ? A1 : Catch;
  • Similar to [[Cast]] but with a custom fallback Catch. If it fails, it will enforce Catch instead of A2.

    Parameter A1

    to check against

    Parameter A2

    to try/test with

    Parameter Catch

    to fallback to if the test failed

    Returns

    A1 | Catch

    Example 1

    import {A} from 'ts-toolbelt'
    type test0 = A.Try<'42', string> // '42'
    type test1 = A.Try<'42', number> // never
    type test1 = A.Try<'42', number, 'tried'> // 'tried'

type Type

type Type<A extends any, Id extends Key> = {
[id]: Id;
} & A;
  • Create your own opaque sub-type from a type A

    Parameter A

    to be personalized

    Parameter Id

    to name the sub-type

    Returns

    A new type Type<A, Id>

    Example 1

    import {A} from 'ts-toolbelt'
    type EUR = A.Type<number, 'eur'>
    type USD = A.Type<number, 'usd'>
    let eurWallet = 10 as EUR
    let usdWallet = 15 as USD
    eurWallet = usdWallet // error

type x

type x = typeof _ & {};
  • A placeholder that is used in various ways

namespace Any

module 'out/Any/_api.d.ts' {}

type At

type At<A extends any, K extends Key> = A extends List
? number extends A['length']
? K extends number | `${number}`
? A[never] | undefined
: undefined
: K extends keyof A
? A[K]
: undefined
: unknown extends A
? unknown
: K extends keyof A
? A[K]
: undefined;
  • Get in O the type of a field of key K

    Parameter O

    to extract from

    Parameter K

    to extract at

    Returns

    [[Any]]

    Example 1

    import {O} from 'ts-toolbelt'
    type User = {
    info: {
    name: string
    age: number
    payment: {}
    }
    id: number
    }
    type test0 = O.At<User, 'id'> // number

type Await

type Await<P extends any> = P extends Promise<infer A> ? A : P;
  • Get the result type of a Promise

    Parameter P

    A promise

    Returns

    [[Any]]

    Example 1

    import {C} from 'ts-toolbelt'
    const promise = new Promise<string>((res, rej) => res('x'))
    type test0 = C.Await<typeof promise> // string
    type test1 = C.Await<Promise<number>> // number

type Cast

type Cast<A1 extends any, A2 extends any> = A1 extends A2 ? A1 : A2;
  • Ask TS to re-check that A1 extends A2. And if it fails, A2 will be enforced anyway. Can also be used to add constraints on parameters.

    Parameter A1

    to check against

    Parameter A2

    to cast to

    Returns

    A1 | A2

    Example 1

    import {A} from 'ts-toolbelt'
    type test0 = A.Cast<'42', string> // '42'
    type test1 = A.Cast<'42', number> // number

type Compute

type Compute<A extends any, depth extends Depth = 'deep'> = {
flat: ComputeFlat<A>;
deep: ComputeDeep<A>;
}[depth];
  • Force TS to load a type that has not been computed (to resolve composed types that TS haven't fully resolved, for display purposes mostly).

    Parameter A

    to compute

    Returns

    A

    Example 1

    import {A} from 'ts-toolbelt'
    type test0 = A.Compute<{x: 'x'} & {y: 'y'}> // {x: 'x', y: 'y'}

type Contains

type Contains<A1 extends any, A2 extends any> = Extends<A1, A2> extends 1 ? 1 : 0;
  • Check whether A1 is part of A2 or not. It works like [[Extends]] but [[Boolean]] results are narrowed to [[False]].

    Parameter A1

    Parameter A2

    Returns

    [[Boolean]]

    Example 1

    type test0 = A.Contains<'a' | 'b', 'b'> // False
    type test1 = A.Contains<'a', 'a' | 'b'> // True
    type test2 = A.Contains<{a: string}, {a: string, b: number}> // False
    type test3 = A.Contains<{a: string, b: number}, {a: string}> // True
    type test4 = A.Contains<never, never> // False
    /// Nothing cannot contain nothing, use `A.Equals`

type Equals

type Equals<A1 extends any, A2 extends any> = (<A>() => A extends A2
? 1
: 0) extends <A>() => A extends A1 ? 1 : 0
? 1
: 0;
  • Check whether A1 is equal to A2 or not.

    Parameter A1

    Parameter A2

    Returns

    [[Boolean]]

    Example 1

    import {A} from 'ts-toolbelt'
    type test0 = A.Equals<42 | 0, 42 | 0> // true
    type test1 = A.Equals<{a: string}, {b: string}> // false
    type test3 = A.Equals<{a: string}, {readonly a: string}> // false

type Extends

type Extends<A1 extends any, A2 extends any> = [A1] extends [never]
? 0
: A1 extends A2
? 1
: 0;
  • Check whether A1 is part of A2 or not. The difference with extends is that it forces a [[Boolean]] return.

    Parameter A1

    Parameter A2

    Returns

    [[Boolean]]

    Example 1

    import {A} from 'ts-toolbelt'
    type test0 = A.Extends<'a' | 'b', 'b'> // Boolean
    type test1 = A.Extends<'a', 'a' | 'b'> // True
    type test2 = A.Extends<{a: string}, {a: any}> // True
    type test3 = A.Extends<{a: any}, {a: any, b: any}> // False
    type test4 = A.Extends<never, never> // False
    /// Nothing cannot extend nothing, use `A.Equals`

type Is

type Is<A extends any, A1 extends any, match extends Match = 'default'> = {
default: Extends<A, A1>;
'contains->': Contains<A, A1>;
'extends->': Extends<A, A1>;
'<-contains': Contains<A1, A>;
'<-extends': Extends<A1, A>;
equals: Equals<A1, A>;
}[match];
  • Check whether A is similar to A1 or not. In other words, it is a compact type that bundles [[Equals]], [[Extends]], [[Contains]], comparison types.

    Parameter A

    to be compared

    Parameter A1

    to compare to

    Parameter match

    (?='default') to change precision

    Returns

    [[Boolean]]

    Example 1

    import {A} from 'ts-toolbelt'
    type test0 = A.Is<'a', 'a' | 'b', 'extends->'> // True
    type test1 = A.Is<'a' | 'b', 'a', 'extends->'> // Boolean
    type test2 = A.Is<'a', 'a' | 'b', '<-extends'> // Boolean
    type test3 = A.Is<'a' | 'b', 'a', '<-extends'> // True
    type test4 = A.Is<'a', 'a' | 'b', 'contains->'> // True
    type test5 = A.Is<'a' | 'b', 'a', 'contains->'> // False
    type test6 = A.Is<'a', 'a' | 'b', '<-contains'> // False
    type test7 = A.Is<'a' | 'b', 'a', '<-contains'> // True
    type test8 = A.Is<'a', 'a' | 'b', 'equals'> // False
    type test9 = A.Is<'b' |'a', 'a' | 'b', 'equals'> // True

type Key

type Key = string | number | symbol;
  • Describes index keys for any type

type Keys

type Keys<A extends any> = A extends List
? Exclude<keyof A, keyof any[]> | number
: keyof A;
  • Get the keys of A

    Parameter A

    Returns

    [[Key]]

    Example 1

    ```ts ```

type KnownKeys

type KnownKeys<O extends object> = {
[K in keyof O]: string extends K ? never : number extends K ? never : K;
} extends {
[K in keyof O]: infer U;
}
? U & Keys<O>
: never;
  • Get the known keys of an [[Object]]

    Parameter O

    Returns

    [[Key]]

    Example 1

    ```ts ```

type Promise

type Promise<A extends any> = globalThis.Promise<
A extends globalThis.Promise<infer X> ? X : A
>;
  • Create an asynchronous operation like the original Promise type but this one prevents promises to be wrapped within more promises (not possible).

    Parameter A

    Example 1

    import {A} from 'ts-toolbelt'
    type test0 = A.Promise<Promise<number>> // Promise<number>
    type test1 = Promise<Promise<number>> // Promise<Promise<number>>

type Try

type Try<A1 extends any, A2 extends any, Catch = never> = A1 extends A2 ? A1 : Catch;
  • Similar to [[Cast]] but with a custom fallback Catch. If it fails, it will enforce Catch instead of A2.

    Parameter A1

    to check against

    Parameter A2

    to try/test with

    Parameter Catch

    to fallback to if the test failed

    Returns

    A1 | Catch

    Example 1

    import {A} from 'ts-toolbelt'
    type test0 = A.Try<'42', string> // '42'
    type test1 = A.Try<'42', number> // never
    type test1 = A.Try<'42', number, 'tried'> // 'tried'

type Type

type Type<A extends any, Id extends Key> = {
[id]: Id;
} & A;
  • Create your own opaque sub-type from a type A

    Parameter A

    to be personalized

    Parameter Id

    to name the sub-type

    Returns

    A new type Type<A, Id>

    Example 1

    import {A} from 'ts-toolbelt'
    type EUR = A.Type<number, 'eur'>
    type USD = A.Type<number, 'usd'>
    let eurWallet = 10 as EUR
    let usdWallet = 15 as USD
    eurWallet = usdWallet // error

type x

type x = typeof _ & {};
  • A placeholder that is used in various ways

namespace B

module 'out/Boolean/_api.d.ts' {}

type And

type And<B1 extends Boolean, B2 extends Boolean> = {
0: {
0: 0;
1: 0;
};
1: {
0: 0;
1: 1;
};
}[B1][B2];
  • Logical && operator (behaves like the JS one)

    Parameter B1

    Left-hand side

    Parameter B2

    Right-hand side

    Returns

    [[Boolean]]

    Example 1

    import {B} from 'ts-toolbelt'
    type test0 = B.And<B.True, B.False> // False
    type test1 = B.And<B.True, B.True> // True
    type test2 = B.And<B.True | B.False, B.True> // Boolean

type Not

type Not<B extends Boolean> = {
0: 1;
1: 0;
}[B];
  • Logical ! operator (behaves like the JS one)

    Parameter B

    to negate

    Returns

    [[Boolean]]

    Example 1

    import {B} from 'ts-toolbelt'
    type test0 = B.Not<B.True> // False
    type test1 = B.Not<B.False> // True

type Or

type Or<B1 extends Boolean, B2 extends Boolean> = {
0: {
0: 0;
1: 1;
};
1: {
0: 1;
1: 1;
};
}[B1][B2];
  • Logical || operator (behaves like the JS one)

    Parameter B1

    Left-hand side

    Parameter B2

    Right-hand side

    Returns

    [[Boolean]]

    Example 1

    import {B} from 'ts-toolbelt'
    type test0 = B.Or<B.True, B.False> // True
    type test1 = B.Or<B.True, B.True> // True
    type test2 = B.Or<B.Boolean, B.False> // Boolean

type Xor

type Xor<B1 extends Boolean, B2 extends Boolean> = {
0: {
0: 0;
1: 1;
};
1: {
0: 1;
1: 0;
};
}[B1][B2];
  • Logical ^ operator (behaves like the JS one)

    Parameter B1

    Left-hand side

    Parameter B2

    Right-hand side

    Returns

    [[Boolean]]

    Example 1

    import {B} from 'ts-toolbelt'
    type test0 = B.Xor<B.True, B.True> // False
    type test1 = B.Xor<B.False, B.True> // True
    type test2 = B.Xor<B.Boolean, B.True> // Boolean

namespace Boolean

module 'out/Boolean/_api.d.ts' {}

type And

type And<B1 extends Boolean, B2 extends Boolean> = {
0: {
0: 0;
1: 0;
};
1: {
0: 0;
1: 1;
};
}[B1][B2];
  • Logical && operator (behaves like the JS one)

    Parameter B1

    Left-hand side

    Parameter B2

    Right-hand side

    Returns

    [[Boolean]]

    Example 1

    import {B} from 'ts-toolbelt'
    type test0 = B.And<B.True, B.False> // False
    type test1 = B.And<B.True, B.True> // True
    type test2 = B.And<B.True | B.False, B.True> // Boolean

type Not

type Not<B extends Boolean> = {
0: 1;
1: 0;
}[B];
  • Logical ! operator (behaves like the JS one)

    Parameter B

    to negate

    Returns

    [[Boolean]]

    Example 1

    import {B} from 'ts-toolbelt'
    type test0 = B.Not<B.True> // False
    type test1 = B.Not<B.False> // True

type Or

type Or<B1 extends Boolean, B2 extends Boolean> = {
0: {
0: 0;
1: 1;
};
1: {
0: 1;
1: 1;
};
}[B1][B2];
  • Logical || operator (behaves like the JS one)

    Parameter B1

    Left-hand side

    Parameter B2

    Right-hand side

    Returns

    [[Boolean]]

    Example 1

    import {B} from 'ts-toolbelt'
    type test0 = B.Or<B.True, B.False> // True
    type test1 = B.Or<B.True, B.True> // True
    type test2 = B.Or<B.Boolean, B.False> // Boolean

type Xor

type Xor<B1 extends Boolean, B2 extends Boolean> = {
0: {
0: 0;
1: 1;
};
1: {
0: 1;
1: 0;
};
}[B1][B2];
  • Logical ^ operator (behaves like the JS one)

    Parameter B1

    Left-hand side

    Parameter B2

    Right-hand side

    Returns

    [[Boolean]]

    Example 1

    import {B} from 'ts-toolbelt'
    type test0 = B.Xor<B.True, B.True> // False
    type test1 = B.Xor<B.False, B.True> // True
    type test2 = B.Xor<B.Boolean, B.True> // Boolean

namespace C

module 'out/Class/_api.d.ts' {}

type Class

type Class<P extends List = any[], R extends object = object> = {
new (...args: P): R;
};
  • Alias to create/describe a class

    Parameter P

    its constructor parameters

    Parameter R

    the object it constructs

    Returns

    class

    Example 1

    import {C} from 'ts-toolbelt'
    type test0 = C.Class<[string, number], {a: string, b: number}>
    declare const SomeClass: test0
    const obj = new SomeClass('foo', 42) // {a: string, b: number}

type Instance

type Instance<C extends Class> = C extends Class<any[], infer R> ? R : any;
  • Get the instance type of a class from a class object

    Parameter C

    * *typeof** class

    Returns

    [[Object]]

    Example 1

    import {C} from 'ts-toolbelt'
    /// `create` takes an instance constructor and creates an instance of it
    declare function create<C extends (new (...args: any[]) => any)>(c: C): C.InstanceOf<C>
    class A {}
    class B {}
    let a = create(A) // A
    let b = create(B) // B

type Parameters

type Parameters<C extends Class> = C extends Class<infer P, any> ? P : never;
  • Get the parameters of a class constructor

    Parameter C

    **typeof** class

    Returns

    [[List]]

    Example 1

    import {C} from 'ts-toolbelt'
    type User = C.Class<[string, string], {firstname: string, lastname: string}>
    type test0 = C.Parameters<User> // [string, string]

namespace Class

module 'out/Class/_api.d.ts' {}

type Class

type Class<P extends List = any[], R extends object = object> = {
new (...args: P): R;
};
  • Alias to create/describe a class

    Parameter P

    its constructor parameters

    Parameter R

    the object it constructs

    Returns

    class

    Example 1

    import {C} from 'ts-toolbelt'
    type test0 = C.Class<[string, number], {a: string, b: number}>
    declare const SomeClass: test0
    const obj = new SomeClass('foo', 42) // {a: string, b: number}

type Instance

type Instance<C extends Class> = C extends Class<any[], infer R> ? R : any;
  • Get the instance type of a class from a class object

    Parameter C

    * *typeof** class

    Returns

    [[Object]]

    Example 1

    import {C} from 'ts-toolbelt'
    /// `create` takes an instance constructor and creates an instance of it
    declare function create<C extends (new (...args: any[]) => any)>(c: C): C.InstanceOf<C>
    class A {}
    class B {}
    let a = create(A) // A
    let b = create(B) // B

type Parameters

type Parameters<C extends Class> = C extends Class<infer P, any> ? P : never;
  • Get the parameters of a class constructor

    Parameter C

    **typeof** class

    Returns

    [[List]]

    Example 1

    import {C} from 'ts-toolbelt'
    type User = C.Class<[string, string], {firstname: string, lastname: string}>
    type test0 = C.Parameters<User> // [string, string]

namespace Community

module 'out/Community/_api.d.ts' {}

type IncludesDeep

type IncludesDeep<
O extends object,
M extends any,
match extends Match = 'default',
limit extends number = 10
> = _IncludesDeep<O, M, match, limit> extends infer X ? Cast<X, Boolean> : never;
  • Check whether O, or its sub-objects have fields that match M where the maximum allowed depth is set with limit.

    Parameter O

    to be inspected

    Parameter M

    to check field type

    Parameter match

    (?='default') to change precision

    Parameter limit

    (?='10') to change the check depth

    Returns

    [[Boolean]]

    Example 1

    ```ts ``` millsp, ctrlplusb

type IsLiteral

type IsLiteral<A extends any, kind extends Kind = Kind> = And<
Or<IsStringLiteral<A>, IsNumberLiteral<A>>,
Extends<A, kind>
>;
  • Determine whether A is literal or not

    Parameter A

    to be checked

    Parameter kind

    (?='string' | 'number') to restrict

    Example 1

    import {A} from 'ts-toolbelt'
    type test0 = A.IsLiteral<1 | 2> // 1
    type test1 = A.IsLiteral<1 | 2, string> // 0
    type test2 = A.IsLiteral<1 | '2', string> // 0 | 1
    type test3 = A.IsLiteral<number> // 0

namespace F

module 'out/Function/_api.d.ts' {}

type AutoPath

type AutoPath<O extends any, P extends string, D extends string = '.'> = _AutoPath<
O,
P,
D
>;
  • Auto-complete, validate, and query the string path of an object O

    Parameter O

    to work on

    Parameter P

    path of O

    Parameter D

    (?='.') delimiter for path

    declare function get<O extends object, P extends string>(
    object: O, path: AutoPath<O, P>
    ): Path<O, Split<P, '.'>>
    declare const user: User
    type User = {
    name: string
    friends: User[]
    }
    // works
    const friendName = get(user, 'friends.40.name')
    const friendFriendName = get(user, 'friends.40.friends.12.name')
    // errors
    const friendNames = get(user, 'friends.40.names')
    const friendFriendNames = get(user, 'friends.40.friends.12.names')

type Compose

type Compose<
mode extends Mode = 'sync',
input extends Input = 'multi'
> = IntersectOf<
{
sync: {
multi: ComposeMultiSync;
list: ComposeListSync;
};
async: {
multi: ComposeMultiAsync;
list: ComposeListAsync;
};
}[mode][input]
>;
  • Compose [[Function]]s together

    Parameter mode

    (?='sync') sync/async (this depends on your implementation)

    Parameter input

    (?='multi') whether you want it to take a list or parameters

    Example 1

    ```ts import {F} from 'ts-toolbelt'

    /// If you are looking for creating types for compose /// Composer will check for input & Compose the output declare const compose: F.Compose

    const a = (a1: number) => ${a1} const c = (c1: string[]) => [c1] const b = (b1: string) => [b1]

    compose(c, b, a)(42)

    /// And if you are looking for an async compose type declare const compose: F.Compose<'async'>

    const a = async (a1: number) => ${a1} const b = async (b1: string) => [b1] const c = async (c1: string[]) => [c1]

    await compose(c, b, a)(42)

type Curry

type Curry<F extends Function> = <
P extends Gaps<Parameters<F>>,
G extends List = GapsOf<P, Parameters<F>>,
R extends any = Return<F>
>(
...p: Gaps<Parameters<F>> | P
) => RequiredKeys<G> extends never ? R : Curry<(...p: G) => R>;
  • Curry a [[Function]]

    Parameter F

    to curry

    Returns

    [[Function]]

    Example 1

    import {F} from 'ts-toolbelt'
    /// If you are looking for creating types for `curry`
    /// It handles placeholders and variable arguments
    declare function curry<Fn extends F.Function>(fn: Fn): F.Curry<Fn>

type Exact

type Exact<A, W> = W extends unknown
? A extends W
? A extends Narrowable
? A
: {
[K in keyof A]: K extends keyof W ? Exact<A[K], W[K]> : never;
}
: W
: never;
  • Force A to comply with W. A must be a shape of W. In other words, A must extend W and have the same properties - no more, no less.

    Parameter A

    Parameter W

type Function

type Function<P extends List = any, R extends any = any> = (...args: P) => R;
  • Alias to create a [[Function]]

    Parameter P

    parameters

    Parameter R

    return type

    Returns

    [[Function]]

    Example 1

    import {F} from 'ts-toolbelt'
    type test0 = F.Function<[string, number], boolean>
    /// (args_0: string, args_1: number) => boolean

type Length

type Length<Fn extends Function> = LLength<Parameters<Fn>>;
  • Extract arguments' length from a [[Function]]

    Parameter F

    to extract from

    Returns

    [[String]] or number

    Example 1

    import {F} from 'ts-toolbelt'
    const fn = (a1: any, a2: any) => {}
    type test0 = F.LengthOf<typeof fn> // 2
    type test1 = F.LengthOf<(a1?: any) => any> // 0 | 1
    type test2 = F.LengthOf<(...a: any[]) => any> // number

type Narrow

type Narrow<A extends any> = Try<A, [], NarrowRaw<A>>;
  • Prevent type widening on generic function parameters

    Parameter A

    to narrow

    Returns

    A

    Example 1

    import {F} from 'ts-toolbelt'
    declare function foo<A extends any[]>(x: F.Narrow<A>): A;
    declare function bar<A extends object>(x: F.Narrow<A>): A;
    const test0 = foo(['e', 2, true, {f: ['g', ['h']]}])
    // `A` inferred : ['e', 2, true, {f: ['g']}]
    const test1 = bar({a: 1, b: 'c', d: ['e', 2, true, {f: ['g']}]})
    // `A` inferred : {a: 1, b: 'c', d: ['e', 2, true, {f: ['g']}]}

type NoInfer

type NoInfer<A extends any> = [A][A extends any ? 0 : never];
  • Explain to TS which function parameter has priority for generic inference

    Parameter A

    to de-prioritize

    Returns

    A

    Example 1

    import {F} from 'ts-toolbelt'
    const fn0 = <A extends any>(a0: A, a1: F.NoInfer<A>): A => {
    return {} as unknown as A // just for the example
    }
    const fn1 = <A extends any>(a0: F.NoInfer<A>, a1: A): A => {
    return {} as unknown as A // just for the example
    }
    const fn2 = <A extends any>(a0: F.NoInfer<A>, a1: F.NoInfer<A>): A => {
    return {} as unknown as A // just for the example
    }
    const test0 = fn0('b', 'a') // error: infer priority is `a0`
    const test1 = fn1('b', 'a') // error: infer priority is `a1`
    const test2 = fn2('b', 'a') // works: infer priority is `a0` | `a1`

    See Also

    • https://stackoverflow.com/questions/56687668

type Parameters

type Parameters<F extends Function> = F extends (...args: infer L) => any
? L
: never;
  • Extract parameters from a [[Function]]

    Parameter F

    to extract from

    Returns

    [[List]]

    Example 1

    import {F} from 'ts-toolbelt'
    const fn = (name: string, age: number) => {}
    type test0 = F.ParamsOf<typeof fn> // [string, number]
    type test1 = F.ParamsOf<(name: string, age: number) => {}> // [string, number]

type Pipe

type Pipe<mode extends Mode = 'sync', input extends Input = 'multi'> = IntersectOf<
{
sync: {
multi: PipeMultiSync;
list: PipeListSync;
};
async: {
multi: PipeMultiAsync;
list: PipeListAsync;
};
}[mode][input]
>;
  • Pipe [[Function]]s together

    Parameter mode

    (?='sync') sync/async (this depends on your implementation)

    Parameter input

    (?='multi') whether you want to take a list or multiple parameters

    Returns

    [[Function]]

    Example 1

    import {F} from 'ts-toolbelt'
    /// If you are looking for creating types for `pipe`:
    declare const pipe: F.Pipe
    const a = (a1: number) => `${a1}`
    const b = (b1: string) => [b1]
    const c = (c1: string[]) => [c1]
    pipe(a, b, c)(42)
    /// And if you are looking for an async `pipe` type:
    declare const pipe: F.Pipe<'async'>
    const a = async (a1: number) => `${a1}`
    const b = async (b1: string) => [b1]
    const c = async (c1: string[]) => [c1]
    await pipe(a, b, c)(42)

type Promisify

type Promisify<F extends Function> = (...args: Parameters<F>) => Promise<Return<F>>;
  • Creates a promisified version of a Function F

    Parameter F

    to promisify

    Returns

    async F

    Example 1

    import {F} from 'ts-toolbelt'
    type test0 = F.Promisify<(a: number) => number> // (a: number) => Promise<number>

type Return

type Return<F extends Function> = F extends (...args: List) => infer R ? R : never;
  • Extract the return type of a [[Function]]

    Parameter F

    to extract from

    Returns

    [[Any]]

    Example 1

    import {F} from 'ts-toolbelt'
    const fn = () => true
    type test0 = F.ReturnOf<typeof fn> // boolean
    type test1 = F.ReturnOf<() => true> // true

type UnCurry

type UnCurry<F extends Curry<any>> = F extends Curry<infer UF> ? UF : never;
  • Undoes the work that was done by [[Curry]]

    Parameter F

    to uncurry

    Returns

    [[Function]]

    Example 1

    import {F} from 'ts-toolbelt'
    type test0 = F.Curry<(a: string, b: number) => boolean>
    declare const foo: test0
    const res0 = foo('a') // F.Curry<(b: number) => boolean> & ((b: number) => boolean)
    type test1 = F.UnCurry<test0> // (a: string, b: number) => boolean
    declare const bar: test1
    const res1 = bar('a') // TS2554: Expected 2 arguments, but got 1.

type ValidPath

type ValidPath<O extends object, Path extends List<AKey>> = O extends unknown
? Path extends unknown
? _ValidPath<O, Path>
: never
: never;
  • Replaces invalid parts of a path with never

    Parameter O

    to be inspected

    Parameter Path

    to be validated

    Returns

    [[Index]][]

    Example 1

    import {A, L, O} from 'ts-toolbelt'
    // Get a property in an object `o` at any depth with `path`
    // `A.Cast<P, O.ValidPath<O, P>>` makes sure `path` is valid
    const getAt = <
    O extends object,
    P extends L.List<A.Index>
    >(o: O, path: A.Cast<P, O.ValidPath<O, P>>): O.Path<O, P> => {
    let valueAt = o
    for (const p of path)
    valueAt = valueAt[p]
    return valueAt as any
    }
    const test0 = getAt({a: {b: {c: 1}}}, ['a', 'b'] as const) // {c: number}
    const test1 = getAt({a: {b: {c: 1}}} as const, ['a', 'b'] as const) // {c: 1}
    const test2 = getAt({a: {b: {c: 1}}}, ['x'] as const) // error

namespace Function

module 'out/Function/_api.d.ts' {}

type AutoPath

type AutoPath<O extends any, P extends string, D extends string = '.'> = _AutoPath<
O,
P,
D
>;
  • Auto-complete, validate, and query the string path of an object O

    Parameter O

    to work on

    Parameter P

    path of O

    Parameter D

    (?='.') delimiter for path

    declare function get<O extends object, P extends string>(
    object: O, path: AutoPath<O, P>
    ): Path<O, Split<P, '.'>>
    declare const user: User
    type User = {
    name: string
    friends: User[]
    }
    // works
    const friendName = get(user, 'friends.40.name')
    const friendFriendName = get(user, 'friends.40.friends.12.name')
    // errors
    const friendNames = get(user, 'friends.40.names')
    const friendFriendNames = get(user, 'friends.40.friends.12.names')

type Compose

type Compose<
mode extends Mode = 'sync',
input extends Input = 'multi'
> = IntersectOf<
{
sync: {
multi: ComposeMultiSync;
list: ComposeListSync;
};
async: {
multi: ComposeMultiAsync;
list: ComposeListAsync;
};
}[mode][input]
>;
  • Compose [[Function]]s together

    Parameter mode

    (?='sync') sync/async (this depends on your implementation)

    Parameter input

    (?='multi') whether you want it to take a list or parameters

    Example 1

    ```ts import {F} from 'ts-toolbelt'

    /// If you are looking for creating types for compose /// Composer will check for input & Compose the output declare const compose: F.Compose

    const a = (a1: number) => ${a1} const c = (c1: string[]) => [c1] const b = (b1: string) => [b1]

    compose(c, b, a)(42)

    /// And if you are looking for an async compose type declare const compose: F.Compose<'async'>

    const a = async (a1: number) => ${a1} const b = async (b1: string) => [b1] const c = async (c1: string[]) => [c1]

    await compose(c, b, a)(42)

type Curry

type Curry<F extends Function> = <
P extends Gaps<Parameters<F>>,
G extends List = GapsOf<P, Parameters<F>>,
R extends any = Return<F>
>(
...p: Gaps<Parameters<F>> | P
) => RequiredKeys<G> extends never ? R : Curry<(...p: G) => R>;
  • Curry a [[Function]]

    Parameter F

    to curry

    Returns

    [[Function]]

    Example 1

    import {F} from 'ts-toolbelt'
    /// If you are looking for creating types for `curry`
    /// It handles placeholders and variable arguments
    declare function curry<Fn extends F.Function>(fn: Fn): F.Curry<Fn>

type Exact

type Exact<A, W> = W extends unknown
? A extends W
? A extends Narrowable
? A
: {
[K in keyof A]: K extends keyof W ? Exact<A[K], W[K]> : never;
}
: W
: never;
  • Force A to comply with W. A must be a shape of W. In other words, A must extend W and have the same properties - no more, no less.

    Parameter A

    Parameter W

type Function

type Function<P extends List = any, R extends any = any> = (...args: P) => R;
  • Alias to create a [[Function]]

    Parameter P

    parameters

    Parameter R

    return type

    Returns

    [[Function]]

    Example 1

    import {F} from 'ts-toolbelt'
    type test0 = F.Function<[string, number], boolean>
    /// (args_0: string, args_1: number) => boolean

type Length

type Length<Fn extends Function> = LLength<Parameters<Fn>>;
  • Extract arguments' length from a [[Function]]

    Parameter F

    to extract from

    Returns

    [[String]] or number

    Example 1

    import {F} from 'ts-toolbelt'
    const fn = (a1: any, a2: any) => {}
    type test0 = F.LengthOf<typeof fn> // 2
    type test1 = F.LengthOf<(a1?: any) => any> // 0 | 1
    type test2 = F.LengthOf<(...a: any[]) => any> // number

type Narrow

type Narrow<A extends any> = Try<A, [], NarrowRaw<A>>;
  • Prevent type widening on generic function parameters

    Parameter A

    to narrow

    Returns

    A

    Example 1

    import {F} from 'ts-toolbelt'
    declare function foo<A extends any[]>(x: F.Narrow<A>): A;
    declare function bar<A extends object>(x: F.Narrow<A>): A;
    const test0 = foo(['e', 2, true, {f: ['g', ['h']]}])
    // `A` inferred : ['e', 2, true, {f: ['g']}]
    const test1 = bar({a: 1, b: 'c', d: ['e', 2, true, {f: ['g']}]})
    // `A` inferred : {a: 1, b: 'c', d: ['e', 2, true, {f: ['g']}]}

type NoInfer

type NoInfer<A extends any> = [A][A extends any ? 0 : never];
  • Explain to TS which function parameter has priority for generic inference

    Parameter A

    to de-prioritize

    Returns

    A

    Example 1

    import {F} from 'ts-toolbelt'
    const fn0 = <A extends any>(a0: A, a1: F.NoInfer<A>): A => {
    return {} as unknown as A // just for the example
    }
    const fn1 = <A extends any>(a0: F.NoInfer<A>, a1: A): A => {
    return {} as unknown as A // just for the example
    }
    const fn2 = <A extends any>(a0: F.NoInfer<A>, a1: F.NoInfer<A>): A => {
    return {} as unknown as A // just for the example
    }
    const test0 = fn0('b', 'a') // error: infer priority is `a0`
    const test1 = fn1('b', 'a') // error: infer priority is `a1`
    const test2 = fn2('b', 'a') // works: infer priority is `a0` | `a1`

    See Also

    • https://stackoverflow.com/questions/56687668

type Parameters

type Parameters<F extends Function> = F extends (...args: infer L) => any
? L
: never;
  • Extract parameters from a [[Function]]

    Parameter F

    to extract from

    Returns

    [[List]]

    Example 1

    import {F} from 'ts-toolbelt'
    const fn = (name: string, age: number) => {}
    type test0 = F.ParamsOf<typeof fn> // [string, number]
    type test1 = F.ParamsOf<(name: string, age: number) => {}> // [string, number]

type Pipe

type Pipe<mode extends Mode = 'sync', input extends Input = 'multi'> = IntersectOf<
{
sync: {
multi: PipeMultiSync;
list: PipeListSync;
};
async: {
multi: PipeMultiAsync;
list: PipeListAsync;
};
}[mode][input]
>;
  • Pipe [[Function]]s together

    Parameter mode

    (?='sync') sync/async (this depends on your implementation)

    Parameter input

    (?='multi') whether you want to take a list or multiple parameters

    Returns

    [[Function]]

    Example 1

    import {F} from 'ts-toolbelt'
    /// If you are looking for creating types for `pipe`:
    declare const pipe: F.Pipe
    const a = (a1: number) => `${a1}`
    const b = (b1: string) => [b1]
    const c = (c1: string[]) => [c1]
    pipe(a, b, c)(42)
    /// And if you are looking for an async `pipe` type:
    declare const pipe: F.Pipe<'async'>
    const a = async (a1: number) => `${a1}`
    const b = async (b1: string) => [b1]
    const c = async (c1: string[]) => [c1]
    await pipe(a, b, c)(42)

type Promisify

type Promisify<F extends Function> = (...args: Parameters<F>) => Promise<Return<F>>;
  • Creates a promisified version of a Function F

    Parameter F

    to promisify

    Returns

    async F

    Example 1

    import {F} from 'ts-toolbelt'
    type test0 = F.Promisify<(a: number) => number> // (a: number) => Promise<number>

type Return

type Return<F extends Function> = F extends (...args: List) => infer R ? R : never;
  • Extract the return type of a [[Function]]

    Parameter F

    to extract from

    Returns

    [[Any]]

    Example 1

    import {F} from 'ts-toolbelt'
    const fn = () => true
    type test0 = F.ReturnOf<typeof fn> // boolean
    type test1 = F.ReturnOf<() => true> // true

type UnCurry

type UnCurry<F extends Curry<any>> = F extends Curry<infer UF> ? UF : never;
  • Undoes the work that was done by [[Curry]]

    Parameter F

    to uncurry

    Returns

    [[Function]]

    Example 1

    import {F} from 'ts-toolbelt'
    type test0 = F.Curry<(a: string, b: number) => boolean>
    declare const foo: test0
    const res0 = foo('a') // F.Curry<(b: number) => boolean> & ((b: number) => boolean)
    type test1 = F.UnCurry<test0> // (a: string, b: number) => boolean
    declare const bar: test1
    const res1 = bar('a') // TS2554: Expected 2 arguments, but got 1.

type ValidPath

type ValidPath<O extends object, Path extends List<AKey>> = O extends unknown
? Path extends unknown
? _ValidPath<O, Path>
: never
: never;
  • Replaces invalid parts of a path with never

    Parameter O

    to be inspected

    Parameter Path

    to be validated

    Returns

    [[Index]][]

    Example 1

    import {A, L, O} from 'ts-toolbelt'
    // Get a property in an object `o` at any depth with `path`
    // `A.Cast<P, O.ValidPath<O, P>>` makes sure `path` is valid
    const getAt = <
    O extends object,
    P extends L.List<A.Index>
    >(o: O, path: A.Cast<P, O.ValidPath<O, P>>): O.Path<O, P> => {
    let valueAt = o
    for (const p of path)
    valueAt = valueAt[p]
    return valueAt as any
    }
    const test0 = getAt({a: {b: {c: 1}}}, ['a', 'b'] as const) // {c: number}
    const test1 = getAt({a: {b: {c: 1}}} as const, ['a', 'b'] as const) // {c: 1}
    const test2 = getAt({a: {b: {c: 1}}}, ['x'] as const) // error

namespace I

module 'out/Iteration/_api.d.ts' {}

type Iteration

type Iteration = [
value: number,
sign: '-' | '0' | '+',
prev: keyof IterationMap,
next: keyof IterationMap,
oppo: keyof IterationMap
];
  • An entry of IterationMap

type IterationOf

type IterationOf<N extends number> = `${N}` extends keyof IterationMap
? IterationMap[`${N}`]
: IterationMap['__'];
  • Transform a number into an [[Iteration]] (to use [[Prev]], [[Next]], & [[Pos]])

    Parameter N

    to transform

    Returns

    [[Iteration]]

    Example 1

    import {I} from 'ts-toolbelt'
    type i = I.IterationOf<0> // ["-1", "1", "0", 0, "0"]
    type next = I.Next<i> // ["0", "2", "1", 1, "+"]
    type prev = I.Prev<i> // ["-2", "0", "-1", -1, "-"]
    type nnext = I.Pos<next> // +1
    type nprev = I.Pos<prev> // -1

type Key

type Key<I extends Iteration> = `${I[0]}`;
  • Get the position of I (**string**)

    Parameter I

    to query

    Returns

    [[String]]

    Example 1

    import {I} from 'ts-toolbelt'
    type i = I.IterationOf<'20'>
    type test0 = I.Key<i> // '20'
    type test1 = I.Key<I.Next<i>> // '21'

type Next

type Next<I extends Iteration> = IterationMap[I[3]];
  • Move I's position forward

    Parameter I

    to move

    Returns

    [[Iteration]]

    Example 1

    import {I} from 'ts-toolbelt'
    type i = I.IterationOf<'20'>
    type test0 = I.Pos<i> // 20
    type test1 = I.Pos<I.Next<i>> // 21

type Pos

type Pos<I extends Iteration> = I[0];
  • Get the position of I (**number**)

    Parameter I

    to query

    Returns

    number

    Example 1

    import {I} from 'ts-toolbelt'
    type i = I.IterationOf<'20'>
    type test0 = I.Pos<i> // 20
    type test1 = I.Pos<I.Next<i>> // 21

type Prev

type Prev<I extends Iteration> = IterationMap[I[2]];
  • Move I's position backwards

    Parameter I

    to move

    Returns

    [[Iteration]]

    Example 1

    import {I} from 'ts-toolbelt'
    type i = I.IterationOf<'20'>
    type test0 = I.Pos<i> // 20
    type test1 = I.Pos<I.Prev<i>> // 19

namespace Iteration

module 'out/Iteration/_api.d.ts' {}

type Iteration

type Iteration = [
value: number,
sign: '-' | '0' | '+',
prev: keyof IterationMap,
next: keyof IterationMap,
oppo: keyof IterationMap
];
  • An entry of IterationMap

type IterationOf

type IterationOf<N extends number> = `${N}` extends keyof IterationMap
? IterationMap[`${N}`]
: IterationMap['__'];
  • Transform a number into an [[Iteration]] (to use [[Prev]], [[Next]], & [[Pos]])

    Parameter N

    to transform

    Returns

    [[Iteration]]

    Example 1

    import {I} from 'ts-toolbelt'
    type i = I.IterationOf<0> // ["-1", "1", "0", 0, "0"]
    type next = I.Next<i> // ["0", "2", "1", 1, "+"]
    type prev = I.Prev<i> // ["-2", "0", "-1", -1, "-"]
    type nnext = I.Pos<next> // +1
    type nprev = I.Pos<prev> // -1

type Key

type Key<I extends Iteration> = `${I[0]}`;
  • Get the position of I (**string**)

    Parameter I

    to query

    Returns

    [[String]]

    Example 1

    import {I} from 'ts-toolbelt'
    type i = I.IterationOf<'20'>
    type test0 = I.Key<i> // '20'
    type test1 = I.Key<I.Next<i>> // '21'

type Next

type Next<I extends Iteration> = IterationMap[I[3]];
  • Move I's position forward

    Parameter I

    to move

    Returns

    [[Iteration]]

    Example 1

    import {I} from 'ts-toolbelt'
    type i = I.IterationOf<'20'>
    type test0 = I.Pos<i> // 20
    type test1 = I.Pos<I.Next<i>> // 21

type Pos

type Pos<I extends Iteration> = I[0];
  • Get the position of I (**number**)

    Parameter I

    to query

    Returns

    number

    Example 1

    import {I} from 'ts-toolbelt'
    type i = I.IterationOf<'20'>
    type test0 = I.Pos<i> // 20
    type test1 = I.Pos<I.Next<i>> // 21

type Prev

type Prev<I extends Iteration> = IterationMap[I[2]];
  • Move I's position backwards

    Parameter I

    to move

    Returns

    [[Iteration]]

    Example 1

    import {I} from 'ts-toolbelt'
    type i = I.IterationOf<'20'>
    type test0 = I.Pos<i> // 20
    type test1 = I.Pos<I.Prev<i>> // 19

namespace L

module 'out/List/_api.d.ts' {}

type Append

type Append<L extends List, A extends any> = [...L, A];
  • Add an element A at the end of L.

    Parameter L

    to append to

    Parameter A

    to be added to

    Returns

    [[List]]

    Example 1

    import {L} from 'ts-toolbelt'
    type test0 = L.Append<[1, 2, 3], 4> // [1, 2, 3, 4]
    type test1 = L.Append<[], 'a'> // ['a']
    type test2 = L.Append<readonly ['a', 'b'], 'c'> // ['a', 'b', 'c']
    type test3 = L.Append<[1, 2], [3, 4]> // [1, 2, [3, 4]]

type Assign

type Assign<
L extends List,
Ls extends List<List>,
depth extends Depth = 'flat',
ignore extends object = BuiltIn,
fill extends any = never
> = Cast<OAssign<L, Ls, depth, ignore, fill>, List>;
  • Assign a list of [[List]] into L with [[Merge]]. Merges from left to right, first items get overridden by the next ones (last-in overrides).

    Parameter L

    to assign to

    Parameter Ls

    to assign

    Parameter depth

    (?='flat') 'deep' to do it deeply

    Parameter ignore

    (?=BuiltIn) types not to merge

    Parameter fill

    (?=undefined) types of O to be replaced with ones of O1

    Returns

    [[Object]]

    Example 1

    import {L} from 'ts-toolbelt'
    type test0 = Assign<[1, 2, 3], [[2, 1]]> // [2, 1, 3]
    type test1 = Assign<[], [[1, 2, 3, 4], [2, 4, 6]]> // [2, 4, 6, 4]
    type test2 = Assign<[0, 0, 0, 0, 0], [[0, 1], [0, 2, 0, 4?]]> // [0, 2, 0, 0 | 4, 0]

type AtLeast

type AtLeast<L extends List, K extends Key = Keys<L>> = OAtLeast<
ObjectOf<L>,
`${K & number}` | K
> extends infer U
? U extends unknown
? _ListOf<U & {}>
: never
: never;
  • Make that at least one of the keys K are required in L at a time.

    Parameter L

    to make required

    Parameter K

    (?=keyof L) to choose fields

    Returns

    [[List]] [[Union]]

    Example 1

    import {L} from 'ts-toolbelt'
    type test0 = L.AtLeast<[1, 2, 3], 0> // [1, 2 | undefined, 3 | undefined]
    type test1 = L.AtLeast<[1, 2, 3], 0 | 1> // [1, 2 | undefined, 3 | undefined] | [1 | undefined, 2, 3 | undefined]
    type test2 = L.AtLeast<[1, 2, 3]>
    // | [1, 2, 3]
    // | [1, 2 | undefined, 3 | undefined]
    // | [1 | undefined, 2, 3 | undefined]
    // | [1 | undefined, 2 | undefined, 3]

type Compulsory

type Compulsory<L extends List, depth extends Depth = 'flat'> = Cast<
CompulsoryPart<L, depth>,
List
>;
  • Make that L's fields cannot be [[Nullable]] or [[Optional]] (it's like [[Required]] & [[NonNullable]] at once).

    Parameter L

    to make compulsory

    Parameter depth

    (?='flat') 'deep' to do it deeply

    Returns

    [[List]]

    Example 1

    * import {L} from 'ts-toolbelt'
    type test0 = L.Compulsory<[1, 2, 3?, 4?]> // [1, 2, 3, 4]
    type test1 = L.Compulsory<['a', 'b' | undefined, 'c', 'd', 'e' | null]> // ['a', 'b', 'c', 'd', 'e']

type CompulsoryKeys

type CompulsoryKeys<L extends List> = OCompulsoryKeys<ObjectOf<L>>;
  • Get the keys of L that are [[Compulsory]]

    (⚠️ needs --strictNullChecks enabled)

    Parameter L

    Returns

    [[Key]]

    Example 1

    import {L} from 'ts-toolbelt'
    type test0 = L.CompulsoryKeys<[1, 2, 3]> // {0: 1, 1: 2, 2: 3}

type Concat

type Concat<L extends List, L1 extends List> = [...L, ...L1];
  • Attach L1 at the end of L

    Parameter L

    to concat with

    Parameter L1

    to be attached

    Returns

    [[List]]

    Example 1

    import {L} from 'ts-toolbelt'
    type test0 = L.Concat<[1, 2], [3, 4]> // [1, 2, 3, 4]
    type test1 = L.Concat<[1, 2], [[3], 4]> // [1, 2, [3], 4]
    type test2 = L.Concat<[1, 2], number[]> // [1, 2, ...number[]]
    type test3 = L.Concat<readonly [1, 2], readonly [3]> // [1, 2, 3]

type Diff

type Diff<L extends List, L1 extends List, match extends Match = 'default'> = ListOf<
ODiff<ObjectOf<L>, ObjectOf<L1>, match>
>;
  • Get a [[List]] that is the difference between L & L1 (L's differences have priority over L1's if entries overlap) (If match = 'default', no type checks are done)

    Parameter L

    to check differences with

    Parameter L1

    to check differences against

    Parameter match

    (?='default') to change precision

    Returns

    [[List]]

    Example 1

    ```ts ```

type Drop

type Drop<
L extends List,
N extends number,
way extends Way = '->'
> = L extends unknown ? (N extends unknown ? _Drop<L, N, way> : never) : never;
  • Remove N entries out of L

    Parameter L

    to remove from

    Parameter N

    to remove out

    Parameter way

    (?='->') from front: '->', from end: '<-'

    Returns

    [[List]]

    Example 1

    ```ts ```

type Either

type Either<L extends List, K extends Key, strict extends Boolean = 1> = OEither<
ObjectOf<L>,
`${K & number}` | K,
strict
> extends infer OE
? OE extends unknown
? _ListOf<OE & {}>
: never
: never;
  • Split L into a [[Union]] with K keys in such a way that none of the keys are ever present with one another within the different unions.

    Parameter L

    to split

    Parameter K

    to split with

    Parameter strict

    (?=1) to force excess property checks https://github.com/microsoft/TypeScript/issues/20863

    Returns

    [[List]] [[Union]]

    Example 1

    ```ts ```

type Exclude

type Exclude<
L extends List,
L1 extends List,
match extends Match = 'default'
> = ListOf<OExclude<ObjectOf<L>, ObjectOf<L1>, match>>;
  • Exclude the entries of L1 out of L (If match = 'default', no type checks are done)

    Parameter L

    to remove from

    Parameter L1

    to remove out

    Parameter match

    (?='default') to change precision

    Returns

    [[List]]

    Example 1

    ```ts ```

type ExcludeKeys

type ExcludeKeys<
L extends List,
L1 extends List,
match extends Match = 'default'
> = OExcludeKeys<ObjectOf<L>, ObjectOf<L1>, match>;
  • Exclude the keys of L1 out of the keys of L (If match = 'default', no type checks are done)

    Parameter L

    to remove the keys from

    Parameter L1

    to remove the keys out

    Parameter match

    (?='default') to change precision

    Returns

    [[Key]]

    Example 1

    ```ts ```

type Extract

type Extract<L extends List, From extends number, To extends number> = Pick<
L,
KeySet<From, To>
>;
  • Pick a range of entries (portion) from L

    Parameter L

    to pick from

    Parameter From

    to start with

    Parameter To

    to end with

    Returns

    [[List]]

    Example 1

    ```ts ```

type Filter

type Filter<L extends List, M extends any, match extends Match = 'default'> = ListOf<
OFilter<ObjectOf<L>, M, match>
>;
  • Filter out of L the entries that match M

    Parameter L

    to remove from

    Parameter M

    to select entries

    Parameter match

    (?='default') to change precision

    Returns

    [[List]]

    Example 1

    ```ts ```

type FilterKeys

type FilterKeys<
L extends List,
M extends any,
match extends Match = 'default'
> = OFilterKeys<ObjectOf<L>, M, match>;
  • Filter out the keys of L which entries match M

    Parameter L

    to remove from

    Parameter M

    to select entries

    Parameter match

    (?='default') to change precision

    Returns

    [[Key]]

    Example 1

    ```ts ```

type Flatten

type Flatten<
L extends List,
strict extends Boolean = 1,
limit extends number = number
> = L extends unknown ? _Flatten<L, strict, limit> : never;
  • Remove all dimensions of L (10 max)

    Parameter L

    to un-nest

    Parameter strict

    (?=1) 0 to not preserve tuples

    Parameter limit

    (?=string) to stop un-nesting at

    Returns

    [[List]]

    Example 1

    ```ts ```

type Group

type Group<L extends List, N extends number> = L extends unknown
? N extends unknown
? _Group<L, N>
: never
: never;
  • Split L into sub-[[List]]s every N

    Parameter L

    to group

    Parameter N

    to split at

    Returns

    [[List]]

    Example 1

    ```ts ```

type Has

type Has<
L extends List,
K extends Key,
M extends any = any,
match extends Match = 'default'
> = OHas<ObjectOf<L>, `${K & number}` | K, M, match>;
  • Check whether L has a entry of key K that matches M

    Parameter L

    to be inspected

    Parameter K

    to choose entry

    Parameter M

    (?=any) to check entry type

    Parameter match

    (?='default') to change precision

    Returns

    [[Boolean]]

    Example 1

    ```ts ```

type HasPath

type HasPath<
L extends List,
Path extends List<Key>,
M extends any = any,
match extends Match = 'default'
> = OHasPath<ObjectOf<L>, Path, M, match>;
  • Check whether L has nested entries that match M

    Parameter L

    to be inspected

    Parameter Path

    to be followed

    Parameter M

    (?=any) to check entry type

    Parameter match

    (?='default') to change precision

    Returns

    [[Boolean]]

    Example 1

    ```ts ```

type Head

type Head<L extends List> = Length<L> extends 0 ? never : L[0];
  • Get the first entry of L

    Parameter L

    to extract from

    Returns

    [[Any]]

    Example 1

    ```ts ```

type Includes

type Includes<
L extends List,
M extends any,
match extends Match = 'default'
> = OIncludes<ObjectOf<L>, M, match>;
  • Check whether L has entries that match M

    Parameter L

    to be inspected

    Parameter M

    to check entry type

    Parameter match

    (?='default') to change precision

    Returns

    [[Boolean]]

    Example 1

    ```ts ```

type Intersect

type Intersect<
L extends List,
L1 extends List,
match extends Match = 'default'
> = ListOf<OIntersect<ObjectOf<L>, ObjectOf<L1>, match>>;
  • Get the intersecting entries of L & L1 (If match = 'default', no type checks are done)

    Parameter L

    to check similarities with

    Parameter L1

    to check similarities against

    Returns

    [[List]]

    Example 1

    ```ts ```

type IntersectKeys

type IntersectKeys<
L extends List,
L1 extends List,
match extends Match = 'default'
> = OIntersectKeys<ObjectOf<L>, L1, match>;
  • Get the intersecting entries of L & L1 (If match = 'default', no type checks are done)

    Parameter L

    to check similarities with

    Parameter L1

    to check similarities against

    Returns

    [[Key]]

    Example 1

    ```ts ```

type KeySet

type KeySet<From extends number, To extends number> = UnionOf<Range<From, To, '->'>>;
  • Create a set of keys

    Parameter From

    to start with

    Parameter To

    to end with

    Returns

    [[Key]]

    Example 1

    ```ts ```

type Last

type Last<L extends List> = L[Length<Tail<L>>];
  • Get the last entry of L

    Parameter L

    to extract from

    Returns

    [[Any]]

    Example 1

    ```ts ```

type LastKey

type LastKey<L extends List> = Length<Tail<L>>;
  • Get the last index of L

    Parameter L

    to get from

    Returns

    number

    Example 1

    ```ts ```

type Length

type Length<L extends List> = L['length'];
  • Get the length of L

    Parameter L

    to get length

    Returns

    [[String]] or number

    Example 1

    ```ts ```

type List

type List<A = any> = ReadonlyArray<A>;
  • A [[List]]

    Parameter A

    its type

    Returns

    [[List]]

    Example 1

    type list0 = [1, 2, 3]
    type list1 = number[]

type Longest

type Longest<L extends List, L1 extends List> = L extends unknown
? L1 extends unknown
? {
0: L1;
1: L;
}[Has<keyof L, keyof L1>]
: never
: never;
  • Get the longest [[List]] of L & L1 (L has priority if both lengths are equal)

    Parameter L

    to compare length

    Parameter L1

    to compare length

    Returns

    L | L1

    Example 1

    ```ts ```

type Merge

type Merge<
L extends List,
L1 extends List,
depth extends Depth = 'flat',
ignore extends object = BuiltIn,
fill extends any = undefined
> = Cast<OMerge<L, L1, depth, ignore, fill>, List>;
  • Accurately merge the fields of L with the ones of L1. It is equivalent to the spread operator in JavaScript. [[Union]]s and [[Optional]] fields will be handled gracefully.

    (⚠️ needs --strictNullChecks enabled)

    Parameter L

    to complete

    Parameter L1

    to copy from

    Parameter depth

    (?='flat') 'deep' to do it deeply

    Parameter ignore

    (?=BuiltIn) types not to merge

    Parameter fill

    (?=undefined) types of O to be replaced with ones of O1

    Returns

    [[List]]

    Example 1

    ```ts ```

type MergeAll

type MergeAll<
L extends List,
Ls extends List<List>,
depth extends Depth = 'flat',
ignore extends object = BuiltIn,
fill extends any = undefined
> = Cast<OMergeAll<L, Ls, depth, ignore, fill>, List>;
  • [[Merge]] a list of [[List]]s into L. Merges from left to right, first items get completed by the next ones (last-in completes).

    Parameter L

    to start with

    Parameter Ls

    to merge

    Parameter depth

    (?='flat') 'deep' to do it deeply

    Parameter ignore

    (?=BuiltIn) types not to merge

    Parameter fill

    (?=undefined) types of O to be replaced with ones of O1

    Returns

    [[List]]

    Example 1

    ```ts ```

type Modify

type Modify<L extends List, LMod extends List> = Cast<
{
[K in keyof LMod]: Replace<LMod[K], x, Exclude<At<L, K>, undefined>>;
},
List
>;
  • Modify L with LMod & the [[x]] placeholder

    Parameter L

    to copy from

    Parameter LMod

    to copy to

    Returns

    [[List]]

    Example 1

    ```ts ```

type NonNullable

type NonNullable<
L extends List,
K extends Key = Key,
depth extends Depth = 'flat'
> = Cast<NonNullablePart<L, `${K & number}` | K, depth>, List>;
  • Make some entries of L not nullable (deeply or not)

    Parameter L

    to make non nullable

    Parameter K

    (?=Key) to choose fields

    Parameter depth

    (?='flat') 'deep' to do it deeply

    Returns

    [[List]]

    Example 1

    ```ts ```

type NonNullableKeys

type NonNullableKeys<L extends List> = ONonNullableKeys<ObjectOf<L>>;
  • Get the keys of L that are non-nullable

    Parameter L

    Returns

    [[Key]]

    Example 1

    ```ts ```

type Nullable

type Nullable<L extends List, K extends Key = Key> = Cast<
Update<L, `${K & number}` | K, x | null | undefined>,
List
>;
  • Make some entries of L nullable (deeply or not)

    Parameter L

    to make nullable

    Parameter K

    (?=Key) to choose fields

    Parameter depth

    (?='flat') 'deep' to do it deeply

    Returns

    [[List]]

    Example 1

    ```ts ```

type NullableKeys

type NullableKeys<L extends List> = ONullableKeys<ObjectOf<L>>;
  • Get the keys of L that are nullable

    Parameter L

    Returns

    [[Key]]

    Example 1

    ```ts ```

type ObjectOf

type ObjectOf<O extends List> = O extends unknown
? number extends Length<O>
? _Pick<O, number>
: _Omit<O, keyof any[]>
: never;
  • Transform a [[List]] into an [[Object]] equivalent

    Parameter L

    to transform

    Returns

    [[Object]]

    Example 1

    ```ts ```

type Omit

type Omit<L extends List, K extends Key> = L extends unknown ? _Omit<L, K> : never;
  • Remove out of L the entries of key K

    Parameter L

    to remove from

    Parameter K

    to chose entries

    Returns

    [[List]]

    Example 1

    ```ts ```

type Optional

type Optional<L extends List, depth extends Depth = 'flat'> = Cast<
OptionalPart<L, depth>,
List
>;
  • Make L optional (deeply or not)

    Parameter L

    to make optional

    Parameter depth

    (?='flat') 'deep' to do it deeply

    Returns

    [[List]]

    Example 1

    ```ts ```

type OptionalKeys

type OptionalKeys<L extends List> = OOptionalKeys<ObjectOf<L>>;
  • Get the keys of L that are optional

    Parameter L

    Returns

    [[Key]]

    Example 1

    ```ts ```

type Overwrite

type Overwrite<L extends List, L1 extends object> = Cast<OOverwrite<L, L1>, List>;
  • Update the entries of L with the ones of L1

    Parameter L

    to update

    Parameter L1

    to update with

    Returns

    [[Object]]

    Example 1

    ```ts ```

type Partial

type Partial<L extends List, depth extends Depth = 'flat'> = Cast<
OPartial<L, depth>,
List
>;
  • Make all fields of O optional (deeply or not)

    Parameter L

    to make optional

    Parameter depth

    (?='flat') 'deep' to do it deeply

    Returns

    [[List]]

    Example 1

    import {O} from 'ts-toolbelt'
    type L = [1, 2, 3, [4, [5]]]
    type test0 = O.Partial<L>
    type test1 = O.Partial<L, 'deep'>

type Patch

type Patch<
L extends List,
L1 extends List,
depth extends Depth = 'flat',
ignore extends object = BuiltIn,
fill extends any = never
> = Cast<OPatch<L, L1, depth, ignore, fill>, List>;
  • Complete the fields of L with the ones of L1. This is a version of [[Merge]] that does NOT handle optional fields, it only completes fields of O with the ones of O1 if they don't exist.

    (⚠️ needs --strictNullChecks enabled)

    Parameter L

    to complete

    Parameter L1

    to copy from

    Parameter depth

    (?='flat') 'deep' to do it deeply

    Parameter ignore

    (?=BuiltIn) types not to merge

    Parameter fill

    (?=never) types of O to be replaced with ones of O1

    Returns

    [[List]]

    Example 1

    ```ts ```

type PatchAll

type PatchAll<
O extends List,
Ls extends List<List>,
depth extends Depth = 'flat',
ignore extends object = BuiltIn,
fill extends any = never
> = Cast<OPatchAll<O, Ls, depth, ignore, fill>, List>;
  • [[Patch]] a list of [[List]]s into L. Patches from left to right, first items get completed by the next ones (last-in completes).

    Parameter O

    to start with

    Parameter Os

    to patch

    Parameter depth

    (?='flat') 'deep' to do it deeply

    Parameter ignore

    (?=BuiltIn) types not to merge

    Parameter fill

    (?=never) types of O to be replaced with ones of O1

    Returns

    [[List]]

    Example 1

    ```ts ```

type Path

type Path<L extends List, Path extends List<Key>> = OPath<L, Path>;
  • Get in L the type of nested properties

    Parameter L

    to be inspected

    Parameter Path

    to be followed

    Returns

    [[Any]]

    Example 1

    ```ts ```

type Paths

type Paths<L extends List> = OPaths<ObjectOf<L>>;
  • Get all the possible paths of L (⚠️ this won't work with circular-refs)

    Parameter L

    to be inspected

    Returns

    [[String]][]

    Example 1

    ```ts ```

type Pick

type Pick<L extends List, K extends Key> = L extends unknown ? _Pick<L, K> : never;
  • Extract out of L the entries of key K

    Parameter L

    to extract from

    Parameter K

    to chose entries

    Returns

    [[List]]

    Example 1

    ```ts ```

type Pop

type Pop<L extends List> = L extends
| readonly [...infer LBody, any]
| readonly [...infer LBody, any?]
? LBody
: L;
  • Remove the last element out of L

    Parameter L

    to remove from

    Returns

    [[List]]

    Example 1

    ```ts ```

type Prepend

type Prepend<L extends List, A extends any> = [A, ...L];
  • Add an element A at the beginning of L

    Parameter L

    to append to

    Parameter A

    to be added to

    Returns

    [[List]]

    Example 1

    ```ts ```

type Readonly

type Readonly<L extends List, depth extends Depth = 'flat'> = Cast<
ReadonlyPart<L, depth>,
List
>;
  • Make L readonly (deeply or not)

    Parameter L

    to make readonly

    Parameter depth

    (?='flat') 'deep' to do it deeply

    Returns

    [[List]]

    Example 1

    ```ts ```

type ReadonlyKeys

type ReadonlyKeys<L extends List> = OReadonlyKeys<ObjectOf<L>>;
  • Get the keys of L that are readonly

    Parameter L

    Returns

    [[Key]]

    Example 1

    ```ts ```

type Remove

type Remove<L extends List, From extends number, To extends number> = Omit<
L,
KeySet<From, To>
>;
  • Remove out of L a range of entries

    Parameter L

    to remove from

    Parameter From

    to start from

    Parameter To

    to end with

    Returns

    [[List]]

    Example 1

    ```ts ```

type Repeat

type Repeat<A extends any, N extends number, L extends List = []> = N extends unknown
? L extends unknown
? _Repeat<A, N, L>
: never
: never;
  • Fill a [[List]] with N times A

    Parameter A

    to fill with

    Parameter N

    to repeat it

    Parameter L

    (?=[]) to be filled

    Returns

    [[List]]

    Example 1

    ```ts ```

type Replace

type Replace<
L extends List,
M extends any,
A extends any,
match extends Match = 'default'
> = Cast<OReplace<L, M, A, match>, List>;
  • Update with A the entries of L that match M

    Parameter O

    to update

    Parameter M

    to select fields

    Parameter A

    to update with

    Parameter match

    (?='default') to change precision

    Returns

    [[List]]

    Example 1

    ```ts ```

type Required

type Required<L extends List, depth extends Depth = 'flat'> = Cast<
RequiredPart<L, depth>,
List
>;
  • Make L required (deeply or not)

    Parameter L

    to make required

    Parameter depth

    (?='flat') 'deep' to do it deeply

    Returns

    [[List]]

    Example 1

    ```ts ```

type RequiredKeys

type RequiredKeys<L extends List> = ORequiredKeys<ObjectOf<L>>;
  • Get the keys of L that are readonly

    Parameter L

    Returns

    [[Key]]

    Example 1

    ```ts ```

type Reverse

type Reverse<L extends List> = L extends unknown ? _Reverse<L> : never;
  • Turn a [[List]] the other way around

    Parameter L

    to reverse

    Parameter LO

    (?=[]) to prepend to

    Returns

    [[List]]

    Example 1

    ```ts ```

type Select

type Select<L extends List, M extends any, match extends Match = 'default'> = ListOf<
OSelect<ObjectOf<L>, M, match>
>;
  • Extract the entries of L that match M

    Parameter L

    to extract from

    Parameter M

    to select entries

    Parameter match

    (?='default') to change precision

    Returns

    [[List]]

    Example 1

    ```ts ```

type SelectKeys

type SelectKeys<
L extends List,
M extends any,
match extends Match = 'default'
> = OSelectKeys<ObjectOf<L>, M, match>;
  • Get the keys of L which entries match M

    Parameter L

    to extract from

    Parameter M

    to select entries

    Parameter match

    (?='default') to change precision

    Returns

    [[Key]]

    Example 1

    ```ts ```

type Shortest

type Shortest<L extends List, L1 extends List> = L extends unknown
? L1 extends unknown
? {
0: L1;
1: L;
}[Has<keyof L1, keyof L>]
: never
: never;
  • Get the shortest [[List]] of L & L1 (L has priority if both lengths are equal)

    Parameter L

    to compare length

    Parameter L1

    to compare length

    Returns

    L | L1

    Example 1

    ```ts ```

type Tail

type Tail<L extends List> = L extends readonly []
? L
: L extends readonly [any?, ...infer LTail]
? LTail
: L;
  • Remove the first item out of a [[List]]

    Parameter L

    Returns

    [[List]]

    Example 1

    ```ts ```

type Take

type Take<
L extends List,
N extends number,
way extends Way = '->'
> = L extends unknown ? (N extends unknown ? _Take<L, N, way> : never) : never;
  • Extract N entries out of L

    Parameter L

    to extract from

    Parameter N

    to extract out

    Parameter way

    (?='->') to extract from end

    Returns

    [[List]]

    Example 1

    ```ts ```

type Undefinable

type Undefinable<L extends List, K extends Key = Key> = Cast<
Update<L, `${K & number}` | K, x | undefined>,
List
>;
  • Make some entries of L not undefined (deeply or not)

    Parameter L

    to make non nullable

    Parameter K

    (?=Key) to choose fields

    Returns

    [[List]]

    Example 1

    ```ts ```

type UndefinableKeys

type UndefinableKeys<L extends List> = OUndefinableKeys<ObjectOf<L>>;
  • Get the keys of L that are undefined

    Parameter L

    Returns

    [[Key]]

    Example 1

    ```ts ```

type Unionize

type Unionize<L extends List, L1 extends List, K extends Key = Key> = {
[P in keyof L]: P extends K ? L[P] | At<L1, P> : L[P];
};
  • Make the fields of L union the ones of L1

    Parameter L

    to union from

    Parameter L1

    to union with

    Parameter K

    (?=Key) to do choose fields

    Returns

    [[List]]

    Example 1

    ```ts ```

type UnionOf

type UnionOf<L extends List> = L[number];
  • Transform a [[List]] into an [[Union]]

    Parameter L

    to transform

    Returns

    [[Any]]

    Example 1

    ```ts ```

type UnNest

type UnNest<L extends List, strict extends Boolean = 1> = L extends unknown
? _UnNest<L, strict>
: never;
  • Remove a dimension of L

    Parameter L

    to un-nest

    Parameter strict

    (?=1) 0 to not preserve tuples

    Returns

    [[List]]

    Example 1

    ```ts ```

type Update

type Update<L extends List, K extends Key, A extends any> = Cast<
OUpdate<L, `${K & number}` | K, A>,
List
>;
  • Update in L the entries of key K with A. Use the [[x]] placeholder to get the current field type.

    Parameter L

    to update

    Parameter K

    to chose fields

    Parameter A

    to update with

    Returns

    [[List]]

    Example 1

    ```ts ```

type Writable

type Writable<L extends List, depth extends Depth = 'flat'> = Cast<
WritablePart<L, depth>,
List
>;
  • Make L writable (deeply or not)

    Parameter L

    to make writable

    Parameter depth

    (?='flat') 'deep' to do it deeply

    Returns

    [[List]]

    Example 1

    ```ts ```

type WritableKeys

type WritableKeys<L extends List> = OWritableKeys<ObjectOf<L>>;
  • Get the keys of L that are writable

    Parameter L

    Returns

    [[Key]]

    Example 1

    ```ts ```

type Zip

type Zip<L extends List, L1 extends List> = L extends unknown
? L1 extends unknown
? _Zip<L, L1>
: never
: never;
  • Pair up the entries of L with L1

    Parameter L

    to pair up

    Parameter L1

    to pair up with

    Returns

    [[List]]

    Example 1

    ```ts ```

type ZipObj

type ZipObj<LKeys extends List<Key>, LFields extends List> = LKeys extends unknown
? LFields extends unknown
? _ZipObj<LKeys, LFields>
: never
: never;
  • Create an [[Object]] from [[List]]s of keys & fields

    Parameter LKeys

    its keys

    Parameter LFields

    its fields

    Returns

    [[Object]]

    Example 1

    ```ts ```

namespace List

module 'out/List/_api.d.ts' {}

type Append

type Append<L extends List, A extends any> = [...L, A];
  • Add an element A at the end of L.

    Parameter L

    to append to

    Parameter A

    to be added to

    Returns

    [[List]]

    Example 1

    import {L} from 'ts-toolbelt'
    type test0 = L.Append<[1, 2, 3], 4> // [1, 2, 3, 4]
    type test1 = L.Append<[], 'a'> // ['a']
    type test2 = L.Append<readonly ['a', 'b'], 'c'> // ['a', 'b', 'c']
    type test3 = L.Append<[1, 2], [3, 4]> // [1, 2, [3, 4]]

type Assign

type Assign<
L extends List,
Ls extends List<List>,
depth extends Depth = 'flat',
ignore extends object = BuiltIn,
fill extends any = never
> = Cast<OAssign<<