/** * @since 0.3.0 */ /** * @since 0.3.0 */ export declare type Compact = { [K in keyof A]: A[K]; }; /** * Returns the string literal 'T' if `A` and `B` are equal types, 'F' otherwise * * @example * import { Equals } from 'typelevel-ts' * * export type Result1 = Equals // "T" * export type Result2 = Equals // "F" * * @since 0.3.0 */ export declare type Equals = (() => C extends Compact ? 'T' : 'F') extends () => C extends Compact ? 'T' : 'F' ? 'T' : 'F'; /** * @example * import { Overwrite } from 'typelevel-ts' * * export type Result = Overwrite<{ a: string; b: number }, { b: boolean }> // { a: string; b: boolean } * * @since 0.3.0 */ export declare type Overwrite = Compact & B>; /** * @example * import { Diff } from 'typelevel-ts' * * export type Result = Diff<{ a: string; b: number }, 'b'> // { a: string; b?: number } * * @since 0.3.0 */ export declare type Diff = Compact<{ [K in Exclude]: A[K]; } & { [K in OK]?: A[K]; }>; /** * Picks only the keys of a certain type * * @example * import { KeysOfType } from 'typelevel-ts' * * export type Result = KeysOfType<{a: string, b: string | boolean, c: boolean, d: string}, string> // "a" | "d" * * @since 0.3.0 */ export declare type KeysOfType = { [K in keyof A]-?: A[K] extends B ? K : never; }[keyof A]; /** * Encodes the constraint that a given object `A` does not contain specific keys `K` * * @example * import { RowLacks } from 'typelevel-ts' * * // function f(x: RowLacks<{ a: string; b: number }, 'a' | 'b'>): void {} * // $ExpectError * // f({ a: 'a', b: 1 }) * function g(x: RowLacks<{ a: string; b: number }, 'c'>): void {} * g({ a: 'a', b: 1 }) // ok * * @since 0.3.0 */ export declare type RowLacks = A & Record, never>; /** * @example * import { Exact } from 'typelevel-ts' * * function f>(a: T): void {} * f({ a: 'a' }) * // $ExpectError * // f({ a: 'a', b: 1 }) * * @since 0.3.0 */ export declare type Exact = A & Record, never>; /** * @example * import { AnyTuple } from 'typelevel-ts' * * function f(x: T): T { * return x * } * const x: [number] = [1] * const y: [number, string] = [1, 'a'] * const z: [number, string, boolean] = [1, 'a', true] * f(x) * f(y) * f(z) * // $ExpectError * // f([1, 2, 3]) * * @since 0.3.0 */ export declare type AnyTuple = Array & { '0': any; }; /** * @internal * @since 0.3.0 */ export interface DeepReadonlyArray extends ReadonlyArray> { } /** * @internal * @since 0.3.0 */ export declare type DeepReadonlyObject = { readonly [K in keyof A]: DeepReadonly; }; /** * @example * import { DeepReadonly } from 'typelevel-ts' * * interface Foo { * bar: { * baz: string * quux: Array<{ barbaz: number }> * } * } * * type ReadonlyFoo = DeepReadonly * export declare const x: ReadonlyFoo * // $ExpectError * // x.bar.quux[1].barbaz = 1 * * @since 0.3.0 */ export declare type DeepReadonly = A extends Array ? DeepReadonlyArray : DeepReadonlyObject; /** * Extracts the type of a member of a tagged union * * @example * import { TaggedUnionMember } from 'typelevel-ts' * * type A = { tag: 'A'; a: string } * type B = { tag: 'B'; b: number } * type C = A | B * export type Result = TaggedUnionMember // A * * @since 0.3.0 */ export declare type TaggedUnionMember = Extract>; /** * Extracts required keys as a literal type union * * @example * import { RequiredKeys } from 'typelevel-ts' * * type A = { a: string; b: number; x?: string; y?: number } * export type Result = RequiredKeys // "a" | "b" * * @since 0.3.0 */ export declare type RequiredKeys = { [K in keyof T]: {} extends Pick ? never : K; } extends { [_ in keyof T]: infer U; } ? {} extends U ? never : U : never; /** * Extracts optional keys as a literal type union * * @example * import { OptionalKeys } from 'typelevel-ts' * * type A = { a: string; b: number; x?: string; y?: number } * export type Result = OptionalKeys // "x" | "y" * * @since 0.3.0 */ export declare type OptionalKeys = { [K in keyof T]: T extends Record ? never : K; } extends { [_ in keyof T]: infer U; } ? {} extends U ? never : U : never;