@@ -315,3 +315,106 @@ type T62<T> = U extends (infer U)[] ? U : U; // Error
315
315
>U : Symbol(U, Decl(inferTypes1.ts, 71, 30))
316
316
>U : Symbol(U, Decl(inferTypes1.ts, 71, 30))
317
317
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
+
0 commit comments