UNPKG

@cuppachino/type-space

Version:

A collection of type utilities for TypeScript.

19 lines (18 loc) 581 B
import type { Combine } from './combine'; /** * A Subset `⊆` is Union between a "Pick" and indexed access. * * @example Be careful when `K` is a union of keys. * ```ts * type Person = { name?: string, age: number, address: { street: string, city: string } } * * declare const arg: Subset<Person, 'name' | 'address'> * declare const expect: * | string * | { street: string; city: string; } * | { name?: string | undefined; address: { street: string; city: string; }; } * | undefined * * ``` */ export type Subset<T, K extends keyof T> = T[K] | Combine<Pick<T, K>>;