UNPKG

@cuppachino/type-space

Version:

A collection of type utilities for TypeScript.

19 lines (18 loc) 563 B
import type { MergeAllRight } from './merge-all-right'; /** * From a tuple of keys and a tuple of values, create a new record. An ordered tuple must be used, and they both must be equal length. * * @example * ```ts * type Key2 = ['a', 'b'] * type v2 = ['apple', 'butter'] * * type Zipped = Zip<Key2, v2> * // { a: "apple"; b: "butter"; } * ``` */ export type Zip<Keys extends readonly string[], Values extends readonly unknown[]> = MergeAllRight<{ [I in keyof Keys]: I extends keyof Values ? { [K in Keys[I]]: Values[I]; } : never; }>;