File: propertyAccessWidening.errors.txt

package info (click to toggle)
node-typescript 5.0.4%2Bds1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 459,140 kB
  • sloc: javascript: 1,972,754; makefile: 6; sh: 1
file content (34 lines) | stat: -rw-r--r-- 1,755 bytes parent folder | download | duplicates (4)
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
tests/cases/conformance/expressions/propertyAccess/propertyAccessWidening.ts(18,21): error TS2339: Property 'a' does not exist on type '{ a: string; b: number; } | {}'.
  Property 'a' does not exist on type '{}'.
tests/cases/conformance/expressions/propertyAccess/propertyAccessWidening.ts(19,5): error TS7053: Element implicitly has an 'any' type because expression of type '"a"' can't be used to index type '{}'.
  Property 'a' does not exist on type '{}'.


==== tests/cases/conformance/expressions/propertyAccess/propertyAccessWidening.ts (2 errors) ====
    // Repro from #31762
    
    function g1(headerNames: any) {
        let t = [{ hasLineBreak: false, cells: [] }];
        const table = [{cells: headerNames }].concat(t);
    }
    
    function g2(headerNames: any) {
        let t = [{ hasLineBreak: false, cells: [] }];
        const table = [{cells: headerNames }]["concat"](t);
    }
    
    // Object in property or element access is widened when target of assignment
    
    function foo(options?: { a: string, b: number }) {
        let x1 = (options || {}).a;     // Object type not widened
        let x2 = (options || {})["a"];  // Object type not widened
        (options || {}).a = 1;          // Object type widened, error
                        ~
!!! error TS2339: Property 'a' does not exist on type '{ a: string; b: number; } | {}'.
!!! error TS2339:   Property 'a' does not exist on type '{}'.
        (options || {})["a"] = 1;       // Object type widened, error
        ~~~~~~~~~~~~~~~~~~~~
!!! error TS7053: Element implicitly has an 'any' type because expression of type '"a"' can't be used to index type '{}'.
!!! error TS7053:   Property 'a' does not exist on type '{}'.
    }