File: recursiveConditionalTypes2.types

package info (click to toggle)
node-typescript 5.2.2-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 497,488 kB
  • sloc: javascript: 2,107,274; makefile: 6; sh: 1
file content (108 lines) | stat: -rw-r--r-- 2,965 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
//// [tests/cases/compiler/recursiveConditionalTypes2.ts] ////

=== recursiveConditionalTypes2.ts ===
// repro from https://github.com/microsoft/TypeScript/issues/43877

type UnionToIntersection<U> = (
>UnionToIntersection : UnionToIntersection<U>

  U extends any ? (k: U) => unknown : never
>k : U

) extends (k: infer I) => unknown
>k : I

  ? I
  : never;

interface ClassSpec {
  public?: object;
>public : object | undefined

  private?: object;
>private : object | undefined

  publicExtends?: Record<string, ClassSpec>;
>publicExtends : Record<string, ClassSpec> | undefined

  privateExtends?: Record<string, ClassSpec>;
>privateExtends : Record<string, ClassSpec> | undefined
}

type MaybeMergePrivateSuperSpec<T> = T extends Record<string, ClassSpec>
>MaybeMergePrivateSuperSpec : MaybeMergePrivateSuperSpec<T>

  ? MergePrivateSuperSpec<T>
  : {};

type MaybeMergePrivateSpecs<T extends ClassSpec, U> = U extends ClassSpec
>MaybeMergePrivateSpecs : MaybeMergePrivateSpecs<T, U>

  ? MergePrivateSpecs<U, T>
  : T;

type MergePrivateSpecs<T extends ClassSpec, U extends ClassSpec> = {
>MergePrivateSpecs : MergePrivateSpecs<T, U>

  public: T["public"] & U["public"];
>public : T["public"] & U["public"]

  private: T["private"] & U["private"];
>private : T["private"] & U["private"]

};

type MergePrivateSuperSpec<T extends Record<string, ClassSpec>> =
>MergePrivateSuperSpec : MergePrivateSuperSpec<T>

  UnionToIntersection<
    {
      [P in keyof T]: SimplifyPrivateSpec<T[P]>;
    }[keyof T]
  >;

export type SimplifyPrivateSpec<T extends ClassSpec> = MaybeMergePrivateSpecs<
>SimplifyPrivateSpec : SimplifyPrivateSpec<T>

  MaybeMergePrivateSpecs<T, MaybeMergePrivateSuperSpec<T["publicExtends"]>>,
  MaybeMergePrivateSuperSpec<T["privateExtends"]>
>;

// repro from https://github.com/microsoft/TypeScript/issues/43877#issuecomment-866146516

type Converted<T> = {
>Converted : Converted<T>

  [P in keyof T]: null extends T[P] ? T[P] : T[P];
};

type DefaultsDeep<T, U extends T> = {
>DefaultsDeep : DefaultsDeep<T, U>

  [P in keyof T]-?: U[P] extends T[P]
    ? null extends U[P]
      ? Converted<DefaultsDeep<T[P], NonNullable<U[P]>>>
      : T[P]
    : T[P];
};

interface _Array<T> {
  find<S extends T>(predicate: (value: T) => boolean): void;
>find : <S extends T>(predicate: (value: T) => boolean) => void
>predicate : (value: T) => boolean
>value : T
}

const z: _Array<DefaultsDeep<{}, {}>> = [];
>z : _Array<DefaultsDeep<{}, {}>>
>[] : never[]

z.find((_) => true);
>z.find((_) => true) : void
>z.find : <S extends DefaultsDeep<{}, {}>>(predicate: (value: DefaultsDeep<{}, {}>) => boolean) => void
>z : _Array<DefaultsDeep<{}, {}>>
>find : <S extends DefaultsDeep<{}, {}>>(predicate: (value: DefaultsDeep<{}, {}>) => boolean) => void
>(_) => true : (_: DefaultsDeep<{}, {}>) => true
>_ : DefaultsDeep<{}, {}>
>true : true