|
| 1 | +=== tests/cases/compiler/inKeywordNarrowingWithNoUncheckedIndexedAccess.ts === |
| 2 | +declare function invariant(condition: boolean): asserts condition; |
| 3 | +>invariant : Symbol(invariant, Decl(inKeywordNarrowingWithNoUncheckedIndexedAccess.ts, 0, 0)) |
| 4 | +>condition : Symbol(condition, Decl(inKeywordNarrowingWithNoUncheckedIndexedAccess.ts, 0, 27)) |
| 5 | +>condition : Symbol(condition, Decl(inKeywordNarrowingWithNoUncheckedIndexedAccess.ts, 0, 27)) |
| 6 | + |
| 7 | +function f1(obj: Record<string, string>) { |
| 8 | +>f1 : Symbol(f1, Decl(inKeywordNarrowingWithNoUncheckedIndexedAccess.ts, 0, 66)) |
| 9 | +>obj : Symbol(obj, Decl(inKeywordNarrowingWithNoUncheckedIndexedAccess.ts, 2, 12)) |
| 10 | +>Record : Symbol(Record, Decl(lib.es5.d.ts, --, --)) |
| 11 | + |
| 12 | + invariant("test" in obj); |
| 13 | +>invariant : Symbol(invariant, Decl(inKeywordNarrowingWithNoUncheckedIndexedAccess.ts, 0, 0)) |
| 14 | +>obj : Symbol(obj, Decl(inKeywordNarrowingWithNoUncheckedIndexedAccess.ts, 2, 12)) |
| 15 | + |
| 16 | + return obj.test; // string |
| 17 | +>obj : Symbol(obj, Decl(inKeywordNarrowingWithNoUncheckedIndexedAccess.ts, 2, 12)) |
| 18 | +} |
| 19 | + |
| 20 | +function f2(obj: Record<string, string>) { |
| 21 | +>f2 : Symbol(f2, Decl(inKeywordNarrowingWithNoUncheckedIndexedAccess.ts, 5, 1)) |
| 22 | +>obj : Symbol(obj, Decl(inKeywordNarrowingWithNoUncheckedIndexedAccess.ts, 7, 12)) |
| 23 | +>Record : Symbol(Record, Decl(lib.es5.d.ts, --, --)) |
| 24 | + |
| 25 | + if ("test" in obj) { |
| 26 | +>obj : Symbol(obj, Decl(inKeywordNarrowingWithNoUncheckedIndexedAccess.ts, 7, 12)) |
| 27 | + |
| 28 | + return obj.test; // string |
| 29 | +>obj : Symbol(obj, Decl(inKeywordNarrowingWithNoUncheckedIndexedAccess.ts, 7, 12)) |
| 30 | + } |
| 31 | + return "default"; |
| 32 | +} |
| 33 | + |
| 34 | +function f3(obj: Record<string, string>) { |
| 35 | +>f3 : Symbol(f3, Decl(inKeywordNarrowingWithNoUncheckedIndexedAccess.ts, 12, 1)) |
| 36 | +>obj : Symbol(obj, Decl(inKeywordNarrowingWithNoUncheckedIndexedAccess.ts, 14, 12)) |
| 37 | +>Record : Symbol(Record, Decl(lib.es5.d.ts, --, --)) |
| 38 | + |
| 39 | + obj.test; // string | undefined |
| 40 | +>obj : Symbol(obj, Decl(inKeywordNarrowingWithNoUncheckedIndexedAccess.ts, 14, 12)) |
| 41 | + |
| 42 | + if ("test" in obj) { |
| 43 | +>obj : Symbol(obj, Decl(inKeywordNarrowingWithNoUncheckedIndexedAccess.ts, 14, 12)) |
| 44 | + |
| 45 | + obj.test; // string |
| 46 | +>obj : Symbol(obj, Decl(inKeywordNarrowingWithNoUncheckedIndexedAccess.ts, 14, 12)) |
| 47 | + } |
| 48 | + else { |
| 49 | + obj.test; // undefined |
| 50 | +>obj : Symbol(obj, Decl(inKeywordNarrowingWithNoUncheckedIndexedAccess.ts, 14, 12)) |
| 51 | + } |
| 52 | +} |
| 53 | + |
| 54 | +function f4(obj: Record<string, string>) { |
| 55 | +>f4 : Symbol(f4, Decl(inKeywordNarrowingWithNoUncheckedIndexedAccess.ts, 22, 1)) |
| 56 | +>obj : Symbol(obj, Decl(inKeywordNarrowingWithNoUncheckedIndexedAccess.ts, 24, 12)) |
| 57 | +>Record : Symbol(Record, Decl(lib.es5.d.ts, --, --)) |
| 58 | + |
| 59 | + obj.test; // string | undefined |
| 60 | +>obj : Symbol(obj, Decl(inKeywordNarrowingWithNoUncheckedIndexedAccess.ts, 24, 12)) |
| 61 | + |
| 62 | + if (obj.hasOwnProperty("test")) { |
| 63 | +>obj.hasOwnProperty : Symbol(Object.hasOwnProperty, Decl(lib.es5.d.ts, --, --)) |
| 64 | +>obj : Symbol(obj, Decl(inKeywordNarrowingWithNoUncheckedIndexedAccess.ts, 24, 12)) |
| 65 | +>hasOwnProperty : Symbol(Object.hasOwnProperty, Decl(lib.es5.d.ts, --, --)) |
| 66 | + |
| 67 | + obj.test; // string |
| 68 | +>obj : Symbol(obj, Decl(inKeywordNarrowingWithNoUncheckedIndexedAccess.ts, 24, 12)) |
| 69 | + } |
| 70 | + else { |
| 71 | + obj.test; // undefined |
| 72 | +>obj : Symbol(obj, Decl(inKeywordNarrowingWithNoUncheckedIndexedAccess.ts, 24, 12)) |
| 73 | + } |
| 74 | +} |
| 75 | + |
0 commit comments