UNPKG

1.71 kBTypeScriptView Raw
1import { Depth } from '../Object/_Internal';
2import { BuiltIn } from '../Misc/BuiltIn';
3import { Has } from '../Union/Has';
4import { If } from './If';
5import { Key } from './Key';
6/**
7 * @hidden
8 */
9export declare type ComputeRaw<A extends any> = A extends Function ? A : {
10 [K in keyof A]: A[K];
11} & unknown;
12/**
13 * @hidden
14 */
15declare type ComputeFlat<A extends any> = A extends BuiltIn ? A : A extends Array<any> ? A extends Array<Record<Key, any>> ? Array<{
16 [K in keyof A[number]]: A[number][K];
17} & unknown> : A : A extends ReadonlyArray<any> ? A extends ReadonlyArray<Record<Key, any>> ? ReadonlyArray<{
18 [K in keyof A[number]]: A[number][K];
19} & unknown> : A : {
20 [K in keyof A]: A[K];
21} & unknown;
22/**
23 * @hidden
24 */
25declare type ComputeDeep<A extends any, Seen = never> = A extends BuiltIn ? A : If<Has<Seen, A>, A, (A extends Array<any> ? A extends Array<Record<Key, any>> ? Array<{
26 [K in keyof A[number]]: ComputeDeep<A[number][K], A | Seen>;
27} & unknown> : A : A extends ReadonlyArray<any> ? A extends ReadonlyArray<Record<Key, any>> ? ReadonlyArray<{
28 [K in keyof A[number]]: ComputeDeep<A[number][K], A | Seen>;
29} & unknown> : A : {
30 [K in keyof A]: ComputeDeep<A[K], A | Seen>;
31} & unknown)>;
32/**
33 * Force TS to load a type that has not been computed (to resolve composed
34 * types that TS haven't fully resolved, for display purposes mostly).
35 * @param A to compute
36 * @returns `A`
37 * @example
38 * ```ts
39 * import {A} from 'ts-toolbelt'
40 *
41 * type test0 = A.Compute<{x: 'x'} & {y: 'y'}> // {x: 'x', y: 'y'}
42 * ```
43 */
44export declare type Compute<A extends any, depth extends Depth = 'deep'> = {
45 'flat': ComputeFlat<A>;
46 'deep': ComputeDeep<A>;
47}[depth];
48export {};