/** * use this type definition instead of `Function` type constructor */ export declare type AnyFunction = (...args: any[]) => any; /** * simple alias to save you keystrokes when defining JS typed object maps */ export declare type StringMap = { [key: string]: T; }; /** * alias for the construct signature that describes a type which can construct objects of the generic type T and whose constructor function accepts an arbitrary number of parameters of any type */ export declare type Constructor = new (...args: any[]) => T; /** * Supplement/Negative to Pick from standard tslib.d.ts */ export declare type Omit = Pick>; /** * As the name hints, $Diff is the type representing the set difference of A and B, i.e. A \ B, where A and B are both object types. */ export declare type Diff = Pick>; /** * opposite of standard library `NonNullable` */ export declare type Nullable = T extends null | undefined ? T : never; /** * Get only JS primitive types from a type */ export declare type Primitive = T extends object ? never : T; /** * Get non JS primitive types from a type. Opposite of `Primitive` */ export declare type NonPrimitive = T extends object ? T : never; /** * Maybe types accept the provided type as well as null or undefined */ export declare type Maybe = T | null | undefined; /** * Obtain the return type of a constructor function type within array or object. * > Like native lib.d.ts `InstanceType` but for arrays/tuples or objects * * @example * * ```ts * class Foo { hello = 'world' } * class Moo { world = 'hello' } * * const arr: [typeof Foo, typeof Moo] = [Foo, Moo] * const obj: { foo: typeof Foo, moo: typeof Moo } = { foo: Foo, moo: Moo } * * // $ExpectType [Foo, Moo] * type TestArr = InstanceTypes * * // $ExpectType {foo: Foo, moo: Moo} * type TestObj = InstanceTypes * ``` */ export declare type InstanceTypes = { [P in keyof T]: T[P] extends Constructor ? U : never; }; /** * extracts union type from tuple * * @example * * ```ts * type Tuple = [number, string, boolean] * // $ExpectType number | string | boolean * type Test = UnionFromTuple * ``` */ export declare type UnionFromTuple = T extends (infer U)[] ? U : never; /** * Extracts arguments tuple type from a function. * This is useful with React children as a function(render prop) pattern, when implementing HoC * * @example * * ```ts * const funcTestOneArgs = (one: number) => { return } * // $ExpectType [number] * type Test = FunctionArgsTuple * ``` * * @deprecated * Instead use standard library `Parameters` mapped type */ export declare type FunctionArgsTuple = T extends (...args: infer U) => any ? U : never; /** * Represents the union type of all the value types of the enumerable properties in an object Type T */ export declare type Values = T extends { [k: string]: infer V; } ? V : never; /** * Get Proper key types union even from distributed union types. * * `keyof` doesn't work/distribute on union types. This mapped type fixes this issue * * @example * * ```ts * type SomeUnion = { one: number } | { three: string } | { four: boolean } * // $ExpectType 'one' | 'three' | 'four' * type Test = Keys * ``` */ export declare type Keys = T extends any ? keyof T : never; /** * Get proper known keys from object which contains index type `[key:string]: any` * * @example * * ```ts * type MapWithIndexType = { one: number; two: string; [k: string]: any; } * // $ExpectType 'one' | 'two' * type Test = KnownKeys * ``` */ export declare type KnownKeys = { [K in keyof T]: string extends K ? never : number extends K ? never : K; } extends { [_ in keyof T]: infer U; } ? U : never; /** * Get required only known keys from object which contains index type `[key:string]: any` * * @example * * ```ts * type MapWithIndexType = { one: number; two?: string; [k: string]: any; } * // $ExpectType 'one' * type Test = RequiredKnownKeys * ``` */ export declare type RequiredKnownKeys = { [K in keyof T]: {} extends Pick ? never : K; } extends { [_ in keyof T]: infer U; } ? U : never; /** * Get optional only known keys from object which contains index type `[key:string]: any` * * @example * * ```ts * type MapWithIndexType = { one: number; two?: string; [k: string]: any; } * // $ExpectType 'two' * type Test = OptionalKnownKeys * ``` */ export declare type OptionalKnownKeys = { [K in keyof T]: string extends K ? never : number extends K ? never : {} extends Pick ? K : never; } extends { [_ in keyof T]: infer U; } ? U : never; /** * Create nominally typed primitives * * Use this mapped typed for creating types for proper nominal type checking. * 👉 kudos to https://michalzalecki.com/nominal-typing-in-typescript/#approach-4-intersection-types-and-brands * * @example * * ```ts * type USD = Brand * type EUR = Brand * * const usd = 10 as USD * const eur = 10 as EUR * * const gross = (net: USD, tax: USD): USD => (net + tax) as USD * * gross(usd, usd); // ok * gross(eur, usd); // Type '"EUR"' is not assignable to type '"USD"'. * ``` */ export declare type Brand = K & { __brand: T; }; /** * Pick key-values from Base provided by Condition generic type. Generic can be an union. * * **NOTE:** * It doesn't work for undefined | null values. for that use `PickWithType` * * @example * * ```ts * type Person = { id: number; name: string; lastName: string; address: { street: string; nr: number; } load: () => Promise } * * // $ExpectType { id: number; name: string; lastName: string; } * type JsonPrimitive = PickWithTypeUnion * ``` */ export declare type PickWithTypeUnion = Pick; /** * Pick key-values from Base provided by Condition generic type. Generic needs to be one type from `null | undefined | object | string | number | boolean` * * @example * * ```ts * type Person = { id: number; name: string; lastName: string; address: { street: string; nr: number; } load: () => Promise } * * // $ExpectType { id: number; } * type JsonPrimitive = PickWithTypeUnion * * // $ExpectType { street: string | null; city: string | null; } * type NullableValues = PickWithType<{ street: string | null; city: string | null; id?: string }, null > \ * ``` */ export declare type PickWithType = Pick ? Key : never; }[keyof Base]>; //# sourceMappingURL=types.d.ts.map