|
| 1 | +=== tests/cases/compiler/controlFlowFavorAssertedTypeThroughTypePredicate.ts === |
| 2 | +// repro 49988#issuecomment-1192016929 |
| 3 | + |
| 4 | +declare function isObject1(value: unknown): value is Record<string, unknown>; |
| 5 | +>isObject1 : Symbol(isObject1, Decl(controlFlowFavorAssertedTypeThroughTypePredicate.ts, 0, 0)) |
| 6 | +>value : Symbol(value, Decl(controlFlowFavorAssertedTypeThroughTypePredicate.ts, 2, 27)) |
| 7 | +>value : Symbol(value, Decl(controlFlowFavorAssertedTypeThroughTypePredicate.ts, 2, 27)) |
| 8 | +>Record : Symbol(Record, Decl(lib.es5.d.ts, --, --)) |
| 9 | + |
| 10 | +declare const obj1: {}; |
| 11 | +>obj1 : Symbol(obj1, Decl(controlFlowFavorAssertedTypeThroughTypePredicate.ts, 4, 13)) |
| 12 | + |
| 13 | +if (isObject1(obj1)) { |
| 14 | +>isObject1 : Symbol(isObject1, Decl(controlFlowFavorAssertedTypeThroughTypePredicate.ts, 0, 0)) |
| 15 | +>obj1 : Symbol(obj1, Decl(controlFlowFavorAssertedTypeThroughTypePredicate.ts, 4, 13)) |
| 16 | + |
| 17 | + obj1; |
| 18 | +>obj1 : Symbol(obj1, Decl(controlFlowFavorAssertedTypeThroughTypePredicate.ts, 4, 13)) |
| 19 | + |
| 20 | + obj1['attr']; |
| 21 | +>obj1 : Symbol(obj1, Decl(controlFlowFavorAssertedTypeThroughTypePredicate.ts, 4, 13)) |
| 22 | +} |
| 23 | +// check type after conditional block |
| 24 | +obj1; |
| 25 | +>obj1 : Symbol(obj1, Decl(controlFlowFavorAssertedTypeThroughTypePredicate.ts, 4, 13)) |
| 26 | + |
| 27 | +declare const obj2: {} | undefined; |
| 28 | +>obj2 : Symbol(obj2, Decl(controlFlowFavorAssertedTypeThroughTypePredicate.ts, 12, 13)) |
| 29 | + |
| 30 | +if (isObject1(obj2)) { |
| 31 | +>isObject1 : Symbol(isObject1, Decl(controlFlowFavorAssertedTypeThroughTypePredicate.ts, 0, 0)) |
| 32 | +>obj2 : Symbol(obj2, Decl(controlFlowFavorAssertedTypeThroughTypePredicate.ts, 12, 13)) |
| 33 | + |
| 34 | + obj2; |
| 35 | +>obj2 : Symbol(obj2, Decl(controlFlowFavorAssertedTypeThroughTypePredicate.ts, 12, 13)) |
| 36 | + |
| 37 | + obj2['attr']; |
| 38 | +>obj2 : Symbol(obj2, Decl(controlFlowFavorAssertedTypeThroughTypePredicate.ts, 12, 13)) |
| 39 | +} |
| 40 | +// check type after conditional block |
| 41 | +obj2; |
| 42 | +>obj2 : Symbol(obj2, Decl(controlFlowFavorAssertedTypeThroughTypePredicate.ts, 12, 13)) |
| 43 | + |
| 44 | +declare function isObject2(value: unknown): value is {}; |
| 45 | +>isObject2 : Symbol(isObject2, Decl(controlFlowFavorAssertedTypeThroughTypePredicate.ts, 18, 5)) |
| 46 | +>value : Symbol(value, Decl(controlFlowFavorAssertedTypeThroughTypePredicate.ts, 20, 27)) |
| 47 | +>value : Symbol(value, Decl(controlFlowFavorAssertedTypeThroughTypePredicate.ts, 20, 27)) |
| 48 | + |
| 49 | +declare const obj3: Record<string, unknown>; |
| 50 | +>obj3 : Symbol(obj3, Decl(controlFlowFavorAssertedTypeThroughTypePredicate.ts, 22, 13)) |
| 51 | +>Record : Symbol(Record, Decl(lib.es5.d.ts, --, --)) |
| 52 | + |
| 53 | +if (isObject2(obj3)) { |
| 54 | +>isObject2 : Symbol(isObject2, Decl(controlFlowFavorAssertedTypeThroughTypePredicate.ts, 18, 5)) |
| 55 | +>obj3 : Symbol(obj3, Decl(controlFlowFavorAssertedTypeThroughTypePredicate.ts, 22, 13)) |
| 56 | + |
| 57 | + obj3; |
| 58 | +>obj3 : Symbol(obj3, Decl(controlFlowFavorAssertedTypeThroughTypePredicate.ts, 22, 13)) |
| 59 | + |
| 60 | + obj3['attr']; |
| 61 | +>obj3 : Symbol(obj3, Decl(controlFlowFavorAssertedTypeThroughTypePredicate.ts, 22, 13)) |
| 62 | +} |
| 63 | +// check type after conditional block |
| 64 | +obj3; |
| 65 | +>obj3 : Symbol(obj3, Decl(controlFlowFavorAssertedTypeThroughTypePredicate.ts, 22, 13)) |
| 66 | + |
| 67 | +declare const obj4: Record<string, unknown> | undefined; |
| 68 | +>obj4 : Symbol(obj4, Decl(controlFlowFavorAssertedTypeThroughTypePredicate.ts, 30, 13)) |
| 69 | +>Record : Symbol(Record, Decl(lib.es5.d.ts, --, --)) |
| 70 | + |
| 71 | +if (isObject2(obj4)) { |
| 72 | +>isObject2 : Symbol(isObject2, Decl(controlFlowFavorAssertedTypeThroughTypePredicate.ts, 18, 5)) |
| 73 | +>obj4 : Symbol(obj4, Decl(controlFlowFavorAssertedTypeThroughTypePredicate.ts, 30, 13)) |
| 74 | + |
| 75 | + obj4; |
| 76 | +>obj4 : Symbol(obj4, Decl(controlFlowFavorAssertedTypeThroughTypePredicate.ts, 30, 13)) |
| 77 | + |
| 78 | + obj4['attr']; |
| 79 | +>obj4 : Symbol(obj4, Decl(controlFlowFavorAssertedTypeThroughTypePredicate.ts, 30, 13)) |
| 80 | +} |
| 81 | +// check type after conditional block |
| 82 | +obj4; |
| 83 | +>obj4 : Symbol(obj4, Decl(controlFlowFavorAssertedTypeThroughTypePredicate.ts, 30, 13)) |
| 84 | + |
0 commit comments