|
| 1 | +//// [tests/cases/compiler/narrowingNoInfer1.ts] //// |
| 2 | + |
| 3 | +=== narrowingNoInfer1.ts === |
| 4 | +// https://github.com/microsoft/TypeScript/issues/58266 |
| 5 | + |
| 6 | +type TaggedA = { _tag: "a" }; |
| 7 | +>TaggedA : Symbol(TaggedA, Decl(narrowingNoInfer1.ts, 0, 0)) |
| 8 | +>_tag : Symbol(_tag, Decl(narrowingNoInfer1.ts, 2, 16)) |
| 9 | + |
| 10 | +type TaggedB = { _tag: "b" }; |
| 11 | +>TaggedB : Symbol(TaggedB, Decl(narrowingNoInfer1.ts, 2, 29)) |
| 12 | +>_tag : Symbol(_tag, Decl(narrowingNoInfer1.ts, 3, 16)) |
| 13 | + |
| 14 | +type TaggedUnion = TaggedA | TaggedB; |
| 15 | +>TaggedUnion : Symbol(TaggedUnion, Decl(narrowingNoInfer1.ts, 3, 29)) |
| 16 | +>TaggedA : Symbol(TaggedA, Decl(narrowingNoInfer1.ts, 0, 0)) |
| 17 | +>TaggedB : Symbol(TaggedB, Decl(narrowingNoInfer1.ts, 2, 29)) |
| 18 | + |
| 19 | +const m: { result: NoInfer<TaggedUnion> }[] = []; |
| 20 | +>m : Symbol(m, Decl(narrowingNoInfer1.ts, 7, 5)) |
| 21 | +>result : Symbol(result, Decl(narrowingNoInfer1.ts, 7, 10)) |
| 22 | +>NoInfer : Symbol(NoInfer, Decl(lib.es5.d.ts, --, --)) |
| 23 | +>TaggedUnion : Symbol(TaggedUnion, Decl(narrowingNoInfer1.ts, 3, 29)) |
| 24 | + |
| 25 | +function map<A, B>(items: readonly A[], f: (a: NoInfer<A>) => B) { |
| 26 | +>map : Symbol(map, Decl(narrowingNoInfer1.ts, 7, 49)) |
| 27 | +>A : Symbol(A, Decl(narrowingNoInfer1.ts, 9, 13)) |
| 28 | +>B : Symbol(B, Decl(narrowingNoInfer1.ts, 9, 15)) |
| 29 | +>items : Symbol(items, Decl(narrowingNoInfer1.ts, 9, 19)) |
| 30 | +>A : Symbol(A, Decl(narrowingNoInfer1.ts, 9, 13)) |
| 31 | +>f : Symbol(f, Decl(narrowingNoInfer1.ts, 9, 39)) |
| 32 | +>a : Symbol(a, Decl(narrowingNoInfer1.ts, 9, 44)) |
| 33 | +>NoInfer : Symbol(NoInfer, Decl(lib.es5.d.ts, --, --)) |
| 34 | +>A : Symbol(A, Decl(narrowingNoInfer1.ts, 9, 13)) |
| 35 | +>B : Symbol(B, Decl(narrowingNoInfer1.ts, 9, 15)) |
| 36 | + |
| 37 | + return items.map(f); |
| 38 | +>items.map : Symbol(ReadonlyArray.map, Decl(lib.es5.d.ts, --, --)) |
| 39 | +>items : Symbol(items, Decl(narrowingNoInfer1.ts, 9, 19)) |
| 40 | +>map : Symbol(ReadonlyArray.map, Decl(lib.es5.d.ts, --, --)) |
| 41 | +>f : Symbol(f, Decl(narrowingNoInfer1.ts, 9, 39)) |
| 42 | +} |
| 43 | + |
| 44 | +const something = map(m, (_) => |
| 45 | +>something : Symbol(something, Decl(narrowingNoInfer1.ts, 13, 5)) |
| 46 | +>map : Symbol(map, Decl(narrowingNoInfer1.ts, 7, 49)) |
| 47 | +>m : Symbol(m, Decl(narrowingNoInfer1.ts, 7, 5)) |
| 48 | +>_ : Symbol(_, Decl(narrowingNoInfer1.ts, 13, 26)) |
| 49 | + |
| 50 | + _.result._tag === "a" ? { ..._, result: _.result } : null, |
| 51 | +>_.result._tag : Symbol(_tag, Decl(narrowingNoInfer1.ts, 2, 16), Decl(narrowingNoInfer1.ts, 3, 16)) |
| 52 | +>_.result : Symbol(result, Decl(narrowingNoInfer1.ts, 7, 10)) |
| 53 | +>_ : Symbol(_, Decl(narrowingNoInfer1.ts, 13, 26)) |
| 54 | +>result : Symbol(result, Decl(narrowingNoInfer1.ts, 7, 10)) |
| 55 | +>_tag : Symbol(_tag, Decl(narrowingNoInfer1.ts, 2, 16), Decl(narrowingNoInfer1.ts, 3, 16)) |
| 56 | +>_ : Symbol(_, Decl(narrowingNoInfer1.ts, 13, 26)) |
| 57 | +>result : Symbol(result, Decl(narrowingNoInfer1.ts, 14, 33)) |
| 58 | +>_.result : Symbol(result, Decl(narrowingNoInfer1.ts, 7, 10)) |
| 59 | +>_ : Symbol(_, Decl(narrowingNoInfer1.ts, 13, 26)) |
| 60 | +>result : Symbol(result, Decl(narrowingNoInfer1.ts, 7, 10)) |
| 61 | + |
| 62 | +); |
| 63 | + |
| 64 | +declare function test2<T1, T2>(a: T1, b: T2, cb: (thing: NoInfer<T1> | NoInfer<T2>) => void): void; |
| 65 | +>test2 : Symbol(test2, Decl(narrowingNoInfer1.ts, 15, 2)) |
| 66 | +>T1 : Symbol(T1, Decl(narrowingNoInfer1.ts, 17, 23)) |
| 67 | +>T2 : Symbol(T2, Decl(narrowingNoInfer1.ts, 17, 26)) |
| 68 | +>a : Symbol(a, Decl(narrowingNoInfer1.ts, 17, 31)) |
| 69 | +>T1 : Symbol(T1, Decl(narrowingNoInfer1.ts, 17, 23)) |
| 70 | +>b : Symbol(b, Decl(narrowingNoInfer1.ts, 17, 37)) |
| 71 | +>T2 : Symbol(T2, Decl(narrowingNoInfer1.ts, 17, 26)) |
| 72 | +>cb : Symbol(cb, Decl(narrowingNoInfer1.ts, 17, 44)) |
| 73 | +>thing : Symbol(thing, Decl(narrowingNoInfer1.ts, 17, 50)) |
| 74 | +>NoInfer : Symbol(NoInfer, Decl(lib.es5.d.ts, --, --)) |
| 75 | +>T1 : Symbol(T1, Decl(narrowingNoInfer1.ts, 17, 23)) |
| 76 | +>NoInfer : Symbol(NoInfer, Decl(lib.es5.d.ts, --, --)) |
| 77 | +>T2 : Symbol(T2, Decl(narrowingNoInfer1.ts, 17, 26)) |
| 78 | + |
| 79 | +test2({ type: 'a' as const }, { type: 'b' as const }, (thing) => { |
| 80 | +>test2 : Symbol(test2, Decl(narrowingNoInfer1.ts, 15, 2)) |
| 81 | +>type : Symbol(type, Decl(narrowingNoInfer1.ts, 19, 7)) |
| 82 | +>const : Symbol(const) |
| 83 | +>type : Symbol(type, Decl(narrowingNoInfer1.ts, 19, 31)) |
| 84 | +>const : Symbol(const) |
| 85 | +>thing : Symbol(thing, Decl(narrowingNoInfer1.ts, 19, 55)) |
| 86 | + |
| 87 | + if (thing.type === "a") { |
| 88 | +>thing.type : Symbol(type, Decl(narrowingNoInfer1.ts, 19, 7), Decl(narrowingNoInfer1.ts, 19, 31)) |
| 89 | +>thing : Symbol(thing, Decl(narrowingNoInfer1.ts, 19, 55)) |
| 90 | +>type : Symbol(type, Decl(narrowingNoInfer1.ts, 19, 7), Decl(narrowingNoInfer1.ts, 19, 31)) |
| 91 | + |
| 92 | + thing; |
| 93 | +>thing : Symbol(thing, Decl(narrowingNoInfer1.ts, 19, 55)) |
| 94 | + |
| 95 | + } else { |
| 96 | + thing; |
| 97 | +>thing : Symbol(thing, Decl(narrowingNoInfer1.ts, 19, 55)) |
| 98 | + } |
| 99 | +}); |
| 100 | + |
0 commit comments