@@ -4,9 +4,19 @@ deeplyNestedMappedTypes.ts(9,7): error TS2322: Type 'Id<{ x: { y: { z: { a: { b:
44deeplyNestedMappedTypes.ts(17,7): error TS2322: Type 'Id2<{ x: { y: { z: { a: { b: { c: number; }; }; }; }; }; }>' is not assignable to type 'Id2<{ x: { y: { z: { a: { b: { c: string; }; }; }; }; }; }>'.
55 The types of 'x.y.z.a.b.c' are incompatible between these types.
66 Type 'number' is not assignable to type 'string'.
7+ deeplyNestedMappedTypes.ts(69,5): error TS2322: Type '{ level1: { level2: { foo: string; }; }; }[]' is not assignable to type '{ level1: { level2: { foo: string; bar: string; }; }; }[]'.
8+ Type '{ level1: { level2: { foo: string; }; }; }' is not assignable to type '{ level1: { level2: { foo: string; bar: string; }; }; }'.
9+ The types of 'level1.level2' are incompatible between these types.
10+ Property 'bar' is missing in type '{ foo: string; }' but required in type '{ foo: string; bar: string; }'.
11+ deeplyNestedMappedTypes.ts(73,5): error TS2322: Type '{ level1: { level2: { foo: string; }; }; }[]' is not assignable to type 'T'.
12+ 'T' could be instantiated with an arbitrary type which could be unrelated to '{ level1: { level2: { foo: string; }; }; }[]'.
13+ deeplyNestedMappedTypes.ts(77,5): error TS2322: Type '{ level1: { level2: { foo: string; }; }; }[]' is not assignable to type '{ level1: { level2: { foo: string; bar: string; }; }; }[]'.
14+ Type '{ level1: { level2: { foo: string; }; }; }' is not assignable to type '{ level1: { level2: { foo: string; bar: string; }; }; }'.
15+ The types of 'level1.level2' are incompatible between these types.
16+ Property 'bar' is missing in type '{ foo: string; }' but required in type '{ foo: string; bar: string; }'.
717
818
9- ==== deeplyNestedMappedTypes.ts (2 errors) ====
19+ ==== deeplyNestedMappedTypes.ts (5 errors) ====
1020 // Simplified repro from #55535
1121
1222 type Id<T> = { [K in keyof T]: Id<T[K]> };
@@ -60,4 +70,109 @@ deeplyNestedMappedTypes.ts(17,7): error TS2322: Type 'Id2<{ x: { y: { z: { a: {
6070
6171 declare const bar1: Bar1;
6272 const bar2: Bar2 = bar1; // Error expected
73+
74+ // Repro from #56138
75+
76+ export type Input = Static<typeof Input>
77+ export const Input = Type.Object({
78+ level1: Type.Object({
79+ level2: Type.Object({
80+ foo: Type.String(),
81+ })
82+ })
83+ })
84+
85+ export type Output = Static<typeof Output>
86+ export const Output = Type.Object({
87+ level1: Type.Object({
88+ level2: Type.Object({
89+ foo: Type.String(),
90+ bar: Type.String(),
91+ })
92+ })
93+ })
94+
95+ function problematicFunction1(ors: Input[]): Output[] {
96+ return ors; // Error
97+ ~~~~~~
98+ !!! error TS2322: Type '{ level1: { level2: { foo: string; }; }; }[]' is not assignable to type '{ level1: { level2: { foo: string; bar: string; }; }; }[]'.
99+ !!! error TS2322: Type '{ level1: { level2: { foo: string; }; }; }' is not assignable to type '{ level1: { level2: { foo: string; bar: string; }; }; }'.
100+ !!! error TS2322: The types of 'level1.level2' are incompatible between these types.
101+ !!! error TS2322: Property 'bar' is missing in type '{ foo: string; }' but required in type '{ foo: string; bar: string; }'.
102+ !!! related TS2728 deeplyNestedMappedTypes.ts:63:13: 'bar' is declared here.
103+ }
104+
105+ function problematicFunction2<T extends Output[]>(ors: Input[]): T {
106+ return ors; // Error
107+ ~~~~~~
108+ !!! error TS2322: Type '{ level1: { level2: { foo: string; }; }; }[]' is not assignable to type 'T'.
109+ !!! error TS2322: 'T' could be instantiated with an arbitrary type which could be unrelated to '{ level1: { level2: { foo: string; }; }; }[]'.
110+ }
111+
112+ function problematicFunction3(ors: (typeof Input.static)[]): Output[] {
113+ return ors; // Error
114+ ~~~~~~
115+ !!! error TS2322: Type '{ level1: { level2: { foo: string; }; }; }[]' is not assignable to type '{ level1: { level2: { foo: string; bar: string; }; }; }[]'.
116+ !!! error TS2322: Type '{ level1: { level2: { foo: string; }; }; }' is not assignable to type '{ level1: { level2: { foo: string; bar: string; }; }; }'.
117+ !!! error TS2322: The types of 'level1.level2' are incompatible between these types.
118+ !!! error TS2322: Property 'bar' is missing in type '{ foo: string; }' but required in type '{ foo: string; bar: string; }'.
119+ !!! related TS2728 deeplyNestedMappedTypes.ts:63:13: 'bar' is declared here.
120+ }
121+
122+ export type Evaluate<T> = T extends infer O ? { [K in keyof O]: O[K] } : never
123+
124+ export declare const Readonly: unique symbol;
125+ export declare const Optional: unique symbol;
126+ export declare const Hint: unique symbol;
127+ export declare const Kind: unique symbol;
128+
129+ export interface TKind {
130+ [Kind]: string
131+ }
132+ export interface TSchema extends TKind {
133+ [Readonly]?: string
134+ [Optional]?: string
135+ [Hint]?: string
136+ params: unknown[]
137+ static: unknown
138+ }
139+
140+ export type TReadonlyOptional<T extends TSchema> = TOptional<T> & TReadonly<T>
141+ export type TReadonly<T extends TSchema> = T & { [Readonly]: 'Readonly' }
142+ export type TOptional<T extends TSchema> = T & { [Optional]: 'Optional' }
143+
144+ export interface TString extends TSchema {
145+ [Kind]: 'String';
146+ static: string;
147+ type: 'string';
148+ }
149+
150+ export type ReadonlyOptionalPropertyKeys<T extends TProperties> = { [K in keyof T]: T[K] extends TReadonly<TSchema> ? (T[K] extends TOptional<T[K]> ? K : never) : never }[keyof T]
151+ export type ReadonlyPropertyKeys<T extends TProperties> = { [K in keyof T]: T[K] extends TReadonly<TSchema> ? (T[K] extends TOptional<T[K]> ? never : K) : never }[keyof T]
152+ export type OptionalPropertyKeys<T extends TProperties> = { [K in keyof T]: T[K] extends TOptional<TSchema> ? (T[K] extends TReadonly<T[K]> ? never : K) : never }[keyof T]
153+ export type RequiredPropertyKeys<T extends TProperties> = keyof Omit<T, ReadonlyOptionalPropertyKeys<T> | ReadonlyPropertyKeys<T> | OptionalPropertyKeys<T>>
154+ export type PropertiesReducer<T extends TProperties, R extends Record<keyof any, unknown>> = Evaluate<(
155+ Readonly<Partial<Pick<R, ReadonlyOptionalPropertyKeys<T>>>> &
156+ Readonly<Pick<R, ReadonlyPropertyKeys<T>>> &
157+ Partial<Pick<R, OptionalPropertyKeys<T>>> &
158+ Required<Pick<R, RequiredPropertyKeys<T>>>
159+ )>
160+ export type PropertiesReduce<T extends TProperties, P extends unknown[]> = PropertiesReducer<T, {
161+ [K in keyof T]: Static<T[K], P>
162+ }>
163+ export type TPropertyKey = string | number
164+ export type TProperties = Record<TPropertyKey, TSchema>
165+ export interface TObject<T extends TProperties = TProperties> extends TSchema {
166+ [Kind]: 'Object'
167+ static: PropertiesReduce<T, this['params']>
168+ type: 'object'
169+ properties: T
170+ }
171+
172+ export type Static<T extends TSchema, P extends unknown[] = []> = (T & { params: P; })['static']
173+
174+ declare namespace Type {
175+ function Object<T extends TProperties>(object: T): TObject<T>
176+ function String(): TString
177+ }
63178
0 commit comments