1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
|
=== tests/cases/conformance/expressions/propertyAccess/propertyAccessWidening.ts ===
// Repro from #31762
function g1(headerNames: any) {
>g1 : Symbol(g1, Decl(propertyAccessWidening.ts, 0, 0))
>headerNames : Symbol(headerNames, Decl(propertyAccessWidening.ts, 2, 12))
let t = [{ hasLineBreak: false, cells: [] }];
>t : Symbol(t, Decl(propertyAccessWidening.ts, 3, 7))
>hasLineBreak : Symbol(hasLineBreak, Decl(propertyAccessWidening.ts, 3, 14))
>cells : Symbol(cells, Decl(propertyAccessWidening.ts, 3, 35))
const table = [{cells: headerNames }].concat(t);
>table : Symbol(table, Decl(propertyAccessWidening.ts, 4, 9))
>[{cells: headerNames }].concat : Symbol(Array.concat, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
>cells : Symbol(cells, Decl(propertyAccessWidening.ts, 4, 20))
>headerNames : Symbol(headerNames, Decl(propertyAccessWidening.ts, 2, 12))
>concat : Symbol(Array.concat, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
>t : Symbol(t, Decl(propertyAccessWidening.ts, 3, 7))
}
function g2(headerNames: any) {
>g2 : Symbol(g2, Decl(propertyAccessWidening.ts, 5, 1))
>headerNames : Symbol(headerNames, Decl(propertyAccessWidening.ts, 7, 12))
let t = [{ hasLineBreak: false, cells: [] }];
>t : Symbol(t, Decl(propertyAccessWidening.ts, 8, 7))
>hasLineBreak : Symbol(hasLineBreak, Decl(propertyAccessWidening.ts, 8, 14))
>cells : Symbol(cells, Decl(propertyAccessWidening.ts, 8, 35))
const table = [{cells: headerNames }]["concat"](t);
>table : Symbol(table, Decl(propertyAccessWidening.ts, 9, 9))
>cells : Symbol(cells, Decl(propertyAccessWidening.ts, 9, 20))
>headerNames : Symbol(headerNames, Decl(propertyAccessWidening.ts, 7, 12))
>"concat" : Symbol(Array.concat, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
>t : Symbol(t, Decl(propertyAccessWidening.ts, 8, 7))
}
// Object in property or element access is widened when target of assignment
function foo(options?: { a: string, b: number }) {
>foo : Symbol(foo, Decl(propertyAccessWidening.ts, 10, 1))
>options : Symbol(options, Decl(propertyAccessWidening.ts, 14, 13))
>a : Symbol(a, Decl(propertyAccessWidening.ts, 14, 24))
>b : Symbol(b, Decl(propertyAccessWidening.ts, 14, 35))
let x1 = (options || {}).a; // Object type not widened
>x1 : Symbol(x1, Decl(propertyAccessWidening.ts, 15, 7))
>(options || {}).a : Symbol(a, Decl(propertyAccessWidening.ts, 14, 24))
>options : Symbol(options, Decl(propertyAccessWidening.ts, 14, 13))
>a : Symbol(a, Decl(propertyAccessWidening.ts, 14, 24))
let x2 = (options || {})["a"]; // Object type not widened
>x2 : Symbol(x2, Decl(propertyAccessWidening.ts, 16, 7))
>options : Symbol(options, Decl(propertyAccessWidening.ts, 14, 13))
>"a" : Symbol(a, Decl(propertyAccessWidening.ts, 14, 24))
(options || {}).a = 1; // Object type widened, error
>options : Symbol(options, Decl(propertyAccessWidening.ts, 14, 13))
(options || {})["a"] = 1; // Object type widened, error
>options : Symbol(options, Decl(propertyAccessWidening.ts, 14, 13))
>"a" : Symbol(a, Decl(propertyAccessWidening.ts, 14, 24))
}
|