Skip to content

Commit efea19f

Browse files
committed
Accept new baselines
1 parent cac6b5b commit efea19f

File tree

4 files changed

+273
-0
lines changed

4 files changed

+273
-0
lines changed

tests/baselines/reference/inferTypes1.errors.txt

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,4 +108,36 @@ tests/cases/conformance/types/conditional/inferTypes1.ts(72,43): error TS4081: E
108108
!!! error TS2304: Cannot find name 'U'.
109109
~
110110
!!! error TS4081: Exported type alias 'T62' has or is using private name 'U'.
111+
112+
// Example from #21496
113+
114+
type JsonifiedObject<T extends object> = { [K in keyof T]: Jsonified<T[K]> };
115+
116+
type Jsonified<T> =
117+
T extends string | number | boolean | null ? T
118+
: T extends undefined | Function ? never // undefined and functions are removed
119+
: T extends { toJSON(): infer R } ? R // toJSON is called if it exists (e.g. Date)
120+
: T extends object ? JsonifiedObject<T>
121+
: "what is this";
122+
123+
type Example = {
124+
str: "literalstring",
125+
fn: () => void,
126+
date: Date,
127+
customClass: MyClass,
128+
obj: {
129+
prop: "property",
130+
clz: MyClass,
131+
nested: { attr: Date }
132+
},
133+
}
134+
135+
declare class MyClass {
136+
toJSON(): "correct";
137+
}
138+
139+
type JsonifiedExample = Jsonified<Example>;
140+
declare let ex: JsonifiedExample;
141+
const z1: "correct" = ex.customClass;
142+
const z2: string = ex.obj.nested.attr;
111143

tests/baselines/reference/inferTypes1.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,38 @@ type T54 = X3<{ a: (x: number) => void, b: () => void }>; // number
7171
type T60 = infer U; // Error
7272
type T61<T> = infer A extends infer B ? infer C : infer D; // Error
7373
type T62<T> = U extends (infer U)[] ? U : U; // Error
74+
75+
// Example from #21496
76+
77+
type JsonifiedObject<T extends object> = { [K in keyof T]: Jsonified<T[K]> };
78+
79+
type Jsonified<T> =
80+
T extends string | number | boolean | null ? T
81+
: T extends undefined | Function ? never // undefined and functions are removed
82+
: T extends { toJSON(): infer R } ? R // toJSON is called if it exists (e.g. Date)
83+
: T extends object ? JsonifiedObject<T>
84+
: "what is this";
85+
86+
type Example = {
87+
str: "literalstring",
88+
fn: () => void,
89+
date: Date,
90+
customClass: MyClass,
91+
obj: {
92+
prop: "property",
93+
clz: MyClass,
94+
nested: { attr: Date }
95+
},
96+
}
97+
98+
declare class MyClass {
99+
toJSON(): "correct";
100+
}
101+
102+
type JsonifiedExample = Jsonified<Example>;
103+
declare let ex: JsonifiedExample;
104+
const z1: "correct" = ex.customClass;
105+
const z2: string = ex.obj.nested.attr;
74106

75107

76108
//// [inferTypes1.js]
@@ -85,3 +117,5 @@ var C = /** @class */ (function () {
85117
}
86118
return C;
87119
}());
120+
var z1 = ex.customClass;
121+
var z2 = ex.obj.nested.attr;

tests/baselines/reference/inferTypes1.symbols

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,3 +315,106 @@ type T62<T> = U extends (infer U)[] ? U : U; // Error
315315
>U : Symbol(U, Decl(inferTypes1.ts, 71, 30))
316316
>U : Symbol(U, Decl(inferTypes1.ts, 71, 30))
317317

318+
// Example from #21496
319+
320+
type JsonifiedObject<T extends object> = { [K in keyof T]: Jsonified<T[K]> };
321+
>JsonifiedObject : Symbol(JsonifiedObject, Decl(inferTypes1.ts, 71, 44))
322+
>T : Symbol(T, Decl(inferTypes1.ts, 75, 21))
323+
>K : Symbol(K, Decl(inferTypes1.ts, 75, 44))
324+
>T : Symbol(T, Decl(inferTypes1.ts, 75, 21))
325+
>Jsonified : Symbol(Jsonified, Decl(inferTypes1.ts, 75, 77))
326+
>T : Symbol(T, Decl(inferTypes1.ts, 75, 21))
327+
>K : Symbol(K, Decl(inferTypes1.ts, 75, 44))
328+
329+
type Jsonified<T> =
330+
>Jsonified : Symbol(Jsonified, Decl(inferTypes1.ts, 75, 77))
331+
>T : Symbol(T, Decl(inferTypes1.ts, 77, 15))
332+
333+
T extends string | number | boolean | null ? T
334+
>T : Symbol(T, Decl(inferTypes1.ts, 77, 15))
335+
>T : Symbol(T, Decl(inferTypes1.ts, 77, 15))
336+
337+
: T extends undefined | Function ? never // undefined and functions are removed
338+
>T : Symbol(T, Decl(inferTypes1.ts, 77, 15))
339+
>Function : Symbol(Function, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
340+
341+
: T extends { toJSON(): infer R } ? R // toJSON is called if it exists (e.g. Date)
342+
>T : Symbol(T, Decl(inferTypes1.ts, 77, 15))
343+
>toJSON : Symbol(toJSON, Decl(inferTypes1.ts, 80, 17))
344+
>R : Symbol(R, Decl(inferTypes1.ts, 80, 33))
345+
>R : Symbol(R, Decl(inferTypes1.ts, 80, 33))
346+
347+
: T extends object ? JsonifiedObject<T>
348+
>T : Symbol(T, Decl(inferTypes1.ts, 77, 15))
349+
>JsonifiedObject : Symbol(JsonifiedObject, Decl(inferTypes1.ts, 71, 44))
350+
>T : Symbol(T, Decl(inferTypes1.ts, 77, 15))
351+
352+
: "what is this";
353+
354+
type Example = {
355+
>Example : Symbol(Example, Decl(inferTypes1.ts, 82, 21))
356+
357+
str: "literalstring",
358+
>str : Symbol(str, Decl(inferTypes1.ts, 84, 16))
359+
360+
fn: () => void,
361+
>fn : Symbol(fn, Decl(inferTypes1.ts, 85, 25))
362+
363+
date: Date,
364+
>date : Symbol(date, Decl(inferTypes1.ts, 86, 19))
365+
>Date : Symbol(Date, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
366+
367+
customClass: MyClass,
368+
>customClass : Symbol(customClass, Decl(inferTypes1.ts, 87, 15))
369+
>MyClass : Symbol(MyClass, Decl(inferTypes1.ts, 94, 1))
370+
371+
obj: {
372+
>obj : Symbol(obj, Decl(inferTypes1.ts, 88, 25))
373+
374+
prop: "property",
375+
>prop : Symbol(prop, Decl(inferTypes1.ts, 89, 10))
376+
377+
clz: MyClass,
378+
>clz : Symbol(clz, Decl(inferTypes1.ts, 90, 25))
379+
>MyClass : Symbol(MyClass, Decl(inferTypes1.ts, 94, 1))
380+
381+
nested: { attr: Date }
382+
>nested : Symbol(nested, Decl(inferTypes1.ts, 91, 21))
383+
>attr : Symbol(attr, Decl(inferTypes1.ts, 92, 17))
384+
>Date : Symbol(Date, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
385+
386+
},
387+
}
388+
389+
declare class MyClass {
390+
>MyClass : Symbol(MyClass, Decl(inferTypes1.ts, 94, 1))
391+
392+
toJSON(): "correct";
393+
>toJSON : Symbol(MyClass.toJSON, Decl(inferTypes1.ts, 96, 23))
394+
}
395+
396+
type JsonifiedExample = Jsonified<Example>;
397+
>JsonifiedExample : Symbol(JsonifiedExample, Decl(inferTypes1.ts, 98, 1))
398+
>Jsonified : Symbol(Jsonified, Decl(inferTypes1.ts, 75, 77))
399+
>Example : Symbol(Example, Decl(inferTypes1.ts, 82, 21))
400+
401+
declare let ex: JsonifiedExample;
402+
>ex : Symbol(ex, Decl(inferTypes1.ts, 101, 11))
403+
>JsonifiedExample : Symbol(JsonifiedExample, Decl(inferTypes1.ts, 98, 1))
404+
405+
const z1: "correct" = ex.customClass;
406+
>z1 : Symbol(z1, Decl(inferTypes1.ts, 102, 5))
407+
>ex.customClass : Symbol(customClass, Decl(inferTypes1.ts, 87, 15))
408+
>ex : Symbol(ex, Decl(inferTypes1.ts, 101, 11))
409+
>customClass : Symbol(customClass, Decl(inferTypes1.ts, 87, 15))
410+
411+
const z2: string = ex.obj.nested.attr;
412+
>z2 : Symbol(z2, Decl(inferTypes1.ts, 103, 5))
413+
>ex.obj.nested.attr : Symbol(attr, Decl(inferTypes1.ts, 92, 17))
414+
>ex.obj.nested : Symbol(nested, Decl(inferTypes1.ts, 91, 21))
415+
>ex.obj : Symbol(obj, Decl(inferTypes1.ts, 88, 25))
416+
>ex : Symbol(ex, Decl(inferTypes1.ts, 101, 11))
417+
>obj : Symbol(obj, Decl(inferTypes1.ts, 88, 25))
418+
>nested : Symbol(nested, Decl(inferTypes1.ts, 91, 21))
419+
>attr : Symbol(attr, Decl(inferTypes1.ts, 92, 17))
420+

tests/baselines/reference/inferTypes1.types

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,3 +321,107 @@ type T62<T> = U extends (infer U)[] ? U : U; // Error
321321
>U : U
322322
>U : No type information available!
323323

324+
// Example from #21496
325+
326+
type JsonifiedObject<T extends object> = { [K in keyof T]: Jsonified<T[K]> };
327+
>JsonifiedObject : JsonifiedObject<T>
328+
>T : T
329+
>K : K
330+
>T : T
331+
>Jsonified : Jsonified<T>
332+
>T : T
333+
>K : K
334+
335+
type Jsonified<T> =
336+
>Jsonified : Jsonified<T>
337+
>T : T
338+
339+
T extends string | number | boolean | null ? T
340+
>T : T
341+
>null : null
342+
>T : T
343+
344+
: T extends undefined | Function ? never // undefined and functions are removed
345+
>T : T
346+
>Function : Function
347+
348+
: T extends { toJSON(): infer R } ? R // toJSON is called if it exists (e.g. Date)
349+
>T : T
350+
>toJSON : () => R
351+
>R : R
352+
>R : R
353+
354+
: T extends object ? JsonifiedObject<T>
355+
>T : T
356+
>JsonifiedObject : JsonifiedObject<T>
357+
>T : T
358+
359+
: "what is this";
360+
361+
type Example = {
362+
>Example : Example
363+
364+
str: "literalstring",
365+
>str : "literalstring"
366+
367+
fn: () => void,
368+
>fn : () => void
369+
370+
date: Date,
371+
>date : Date
372+
>Date : Date
373+
374+
customClass: MyClass,
375+
>customClass : MyClass
376+
>MyClass : MyClass
377+
378+
obj: {
379+
>obj : { prop: "property"; clz: MyClass; nested: { attr: Date; }; }
380+
381+
prop: "property",
382+
>prop : "property"
383+
384+
clz: MyClass,
385+
>clz : MyClass
386+
>MyClass : MyClass
387+
388+
nested: { attr: Date }
389+
>nested : { attr: Date; }
390+
>attr : Date
391+
>Date : Date
392+
393+
},
394+
}
395+
396+
declare class MyClass {
397+
>MyClass : MyClass
398+
399+
toJSON(): "correct";
400+
>toJSON : () => "correct"
401+
}
402+
403+
type JsonifiedExample = Jsonified<Example>;
404+
>JsonifiedExample : JsonifiedObject<Example>
405+
>Jsonified : Jsonified<T>
406+
>Example : Example
407+
408+
declare let ex: JsonifiedExample;
409+
>ex : JsonifiedObject<Example>
410+
>JsonifiedExample : JsonifiedObject<Example>
411+
412+
const z1: "correct" = ex.customClass;
413+
>z1 : "correct"
414+
>ex.customClass : "correct"
415+
>ex : JsonifiedObject<Example>
416+
>customClass : "correct"
417+
418+
const z2: string = ex.obj.nested.attr;
419+
>z2 : string
420+
>ex.obj.nested.attr : string
421+
>ex.obj.nested : JsonifiedObject<{ attr: Date; }>
422+
>ex.obj : JsonifiedObject<{ prop: "property"; clz: MyClass; nested: { attr: Date; }; }>
423+
>ex : JsonifiedObject<Example>
424+
>obj : JsonifiedObject<{ prop: "property"; clz: MyClass; nested: { attr: Date; }; }>
425+
>nested : JsonifiedObject<{ attr: Date; }>
426+
>attr : string
427+

0 commit comments

Comments
 (0)