|
| 1 | +//// [tests/cases/compiler/contextualTypeSelfReferencing.ts] //// |
| 2 | + |
| 3 | +=== contextualTypeSelfReferencing.ts === |
| 4 | +// repro from https://github.com/microsoft/TypeScript/issues/54048 |
| 5 | + |
| 6 | +type narrow<def> = def extends string |
| 7 | +>narrow : Symbol(narrow, Decl(contextualTypeSelfReferencing.ts, 0, 0)) |
| 8 | +>def : Symbol(def, Decl(contextualTypeSelfReferencing.ts, 2, 12)) |
| 9 | +>def : Symbol(def, Decl(contextualTypeSelfReferencing.ts, 2, 12)) |
| 10 | + |
| 11 | + ? def |
| 12 | +>def : Symbol(def, Decl(contextualTypeSelfReferencing.ts, 2, 12)) |
| 13 | + |
| 14 | + : def extends [unknown, ...unknown[]] |
| 15 | +>def : Symbol(def, Decl(contextualTypeSelfReferencing.ts, 2, 12)) |
| 16 | + |
| 17 | + ? def |
| 18 | +>def : Symbol(def, Decl(contextualTypeSelfReferencing.ts, 2, 12)) |
| 19 | + |
| 20 | + : { |
| 21 | + [k in keyof def]: narrow<def[k]>; |
| 22 | +>k : Symbol(k, Decl(contextualTypeSelfReferencing.ts, 7, 7)) |
| 23 | +>def : Symbol(def, Decl(contextualTypeSelfReferencing.ts, 2, 12)) |
| 24 | +>narrow : Symbol(narrow, Decl(contextualTypeSelfReferencing.ts, 0, 0)) |
| 25 | +>def : Symbol(def, Decl(contextualTypeSelfReferencing.ts, 2, 12)) |
| 26 | +>k : Symbol(k, Decl(contextualTypeSelfReferencing.ts, 7, 7)) |
| 27 | + |
| 28 | + }; |
| 29 | + |
| 30 | +declare const parse: <def>(def: narrow<def>) => def; |
| 31 | +>parse : Symbol(parse, Decl(contextualTypeSelfReferencing.ts, 10, 13)) |
| 32 | +>def : Symbol(def, Decl(contextualTypeSelfReferencing.ts, 10, 22), Decl(contextualTypeSelfReferencing.ts, 10, 27)) |
| 33 | +>def : Symbol(def, Decl(contextualTypeSelfReferencing.ts, 10, 22), Decl(contextualTypeSelfReferencing.ts, 10, 27)) |
| 34 | +>narrow : Symbol(narrow, Decl(contextualTypeSelfReferencing.ts, 0, 0)) |
| 35 | +>def : Symbol(def, Decl(contextualTypeSelfReferencing.ts, 10, 22), Decl(contextualTypeSelfReferencing.ts, 10, 27)) |
| 36 | +>def : Symbol(def, Decl(contextualTypeSelfReferencing.ts, 10, 22), Decl(contextualTypeSelfReferencing.ts, 10, 27)) |
| 37 | + |
| 38 | +const result = parse([{ a: "foo" }]); |
| 39 | +>result : Symbol(result, Decl(contextualTypeSelfReferencing.ts, 12, 5)) |
| 40 | +>parse : Symbol(parse, Decl(contextualTypeSelfReferencing.ts, 10, 13)) |
| 41 | +>a : Symbol(a, Decl(contextualTypeSelfReferencing.ts, 12, 23)) |
| 42 | + |
0 commit comments