/
inferTypeConstraintInstantiationCircularity.types
134 lines (98 loc) · 2.42 KB
/
inferTypeConstraintInstantiationCircularity.types
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
=== tests/cases/compiler/inferTypeConstraintInstantiationCircularity.ts ===
type AMappedType<T> = { [KeyType in keyof T]: number };
>AMappedType : AMappedType<T>
type HasM = {
>HasM : { m: number; }
m: number;
>m : number
};
// Simplified repro from #48059
interface X1<
T extends HasM,
Output = AMappedType<{ s: number; } & { [k in keyof T]: number; }>
>s : number
> {
tee: T;
>tee : T
output: Output;
>output : Output
}
type F1<T> = T extends X1<infer U> ? U : never;
>F1 : F1<T>
// With default inlined
interface X2<
T extends HasM,
Output
> {
tee: T;
>tee : T
output: Output;
>output : Output
}
type F2<T> = T extends X2<infer U, AMappedType<{ s: number; } & { [k in keyof (infer U)]: number; }>> ? U : never;
>F2 : F2<T>
>s : number
// Original repro
type Simplify<T> = {[KeyType in keyof T]: T[KeyType]};
>Simplify : Simplify<T>
type optionalKeys<T extends object> = {
>optionalKeys : optionalKeys<T>
[k in keyof T]: undefined extends T[k] ? k : never;
}[keyof T];
type requiredKeys<T extends object> = Exclude<keyof T, optionalKeys<T>>;
>requiredKeys : requiredKeys<T>
export type addQuestionMarks<T extends object> = {
>addQuestionMarks : addQuestionMarks<T>
[k in optionalKeys<T>]?: T[k];
} & {
[k in requiredKeys<T>]: T[k];
};
type ZodRawShape = {
>ZodRawShape : { [k: string]: ZodType<any>; }
[k: string]: ZodType<any>;
>k : string
};
interface ZodType<Output> {
_type: Output;
>_type : Output
}
interface ZodObject<
T extends ZodRawShape,
Output = Simplify<
{
[k in optionalKeys<T>]?: T[k];
} & {
[k in requiredKeys<T>]: T[k];
}
>
> extends ZodType<Output> {
readonly _shape: T;
>_shape : T
}
type MyObject<T> = T extends ZodObject<infer U>
>MyObject : MyObject<T>
? U extends ZodRawShape
? U
: never
: never;
// Repro from #50479
type Cell<Value extends BaseValue = any, BaseValue = unknown> = {
>Cell : Cell<Value, BaseValue>
id: string
>id : string
}
type Items<Type extends Cell = Cell> = {
>Items : Items<Type>
type: Type
>type : Type
name: string
>name : string
}
type InferIOItemToJSType<T extends Items> =
>InferIOItemToJSType : InferIOItemToJSType<T>
T extends { type: infer U }
>type : U
? U extends Cell<infer V/**, infer _ or unknown, or any valid type **/>
? V
: never
: never