File: noUncheckedIndexedAccessDestructuring.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 (111 lines) | stat: -rw-r--r-- 4,813 bytes parent folder | download | duplicates (2)
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
tests/cases/conformance/pedantic/noUncheckedIndexedAccessDestructuring.ts(8,1): error TS18048: 's1' is possibly 'undefined'.
tests/cases/conformance/pedantic/noUncheckedIndexedAccessDestructuring.ts(12,9): error TS2345: Argument of type 'undefined' is not assignable to parameter of type 'string'.
tests/cases/conformance/pedantic/noUncheckedIndexedAccessDestructuring.ts(16,9): error TS2345: Argument of type 'undefined' is not assignable to parameter of type 'string'.
tests/cases/conformance/pedantic/noUncheckedIndexedAccessDestructuring.ts(23,1): error TS18048: 't1' is possibly 'undefined'.
tests/cases/conformance/pedantic/noUncheckedIndexedAccessDestructuring.ts(26,1): error TS18048: 't2.z' is possibly 'undefined'.
tests/cases/conformance/pedantic/noUncheckedIndexedAccessDestructuring.ts(34,5): error TS18048: 'z' is possibly 'undefined'.
tests/cases/conformance/pedantic/noUncheckedIndexedAccessDestructuring.ts(41,5): error TS18048: 'q.z' is possibly 'undefined'.
tests/cases/conformance/pedantic/noUncheckedIndexedAccessDestructuring.ts(52,5): error TS18048: 'q.z' is possibly 'undefined'.
tests/cases/conformance/pedantic/noUncheckedIndexedAccessDestructuring.ts(62,2): error TS2322: Type 'string | undefined' is not assignable to type 'string'.
  Type 'undefined' is not assignable to type 'string'.
tests/cases/conformance/pedantic/noUncheckedIndexedAccessDestructuring.ts(71,8): error TS2322: Type 'number | undefined' is not assignable to type 'number'.
  Type 'undefined' is not assignable to type 'number'.


==== tests/cases/conformance/pedantic/noUncheckedIndexedAccessDestructuring.ts (10 errors) ====
    declare const strArray: string[];
    declare const strStrTuple: [string, string];
    
    // Declaration forms for array destructuring
    
    // Destructuring from a simple array -> include undefined
    const [s1] = strArray;
    s1.toString(); // Should error, s1 possibly undefined
    ~~
!!! error TS18048: 's1' is possibly 'undefined'.
    
    // Destructuring a rest element -> do not include undefined
    const [...s2] = strArray;
    s2.push(undefined); // Should error, 'undefined' not part of s2's element type
            ~~~~~~~~~
!!! error TS2345: Argument of type 'undefined' is not assignable to parameter of type 'string'.
    
    // Destructuring a rest element -> do not include undefined
    const [, , ...s3] = strArray;
    s3.push(undefined); // Should error, 'undefined' not part of s2's element type
            ~~~~~~~~~
!!! error TS2345: Argument of type 'undefined' is not assignable to parameter of type 'string'.
    
    // Declaration forms for object destructuring
    
    declare const strMap: { [s: string]: string };
    
    const { t1 } = strMap;
    t1.toString(); // Should error, t1 possibly undefined
    ~~
!!! error TS18048: 't1' is possibly 'undefined'.
    
    const { ...t2 } = strMap;
    t2.z.toString(); // Should error
    ~~~~
!!! error TS18048: 't2.z' is possibly 'undefined'.
    
    // Test intersections with declared properties
    declare const numMapPoint: { x: number, y: number} & { [s: string]: number };
    {
        const { x, y, z } = numMapPoint;
        x.toFixed(); // Should OK
        y.toFixed(); // Should OK
        z.toFixed(); // Should error
        ~
!!! error TS18048: 'z' is possibly 'undefined'.
    }
    
    {
        const { x, ...q } = numMapPoint;
        x.toFixed(); // Should OK
        q.y.toFixed(); // Should OK
        q.z.toFixed(); // Should error
        ~~~
!!! error TS18048: 'q.z' is possibly 'undefined'.
    }
    
    {
        const { x, ...q } = numMapPoint;
        x.
        toFixed(); // Should OK
    
        q.
        y.toFixed(); // Should OK
    
        q.
        ~~
        z.toFixed(); // Should error
    ~~~~~
!!! error TS18048: 'q.z' is possibly 'undefined'.
    }
    
    
    declare let target_string: string;
    declare let target_string_undef: string | undefined;
    declare let target_string_arr: string[];
    
    // Assignment forms
    [target_string] = strArray; // Should error
     ~~~~~~~~~~~~~
!!! error TS2322: Type 'string | undefined' is not assignable to type 'string'.
!!! error TS2322:   Type 'undefined' is not assignable to type 'string'.
    [target_string_undef] = strArray;  // Should OK
    [,,, ...target_string_arr] = strArray; // Should OK
    
    {
        let x: number, y: number, z: number | undefined;
        ({ x, y, z } = numMapPoint); // Should OK
    
        let q: number;
        ({ q } = numMapPoint); // Should error
           ~
!!! error TS2322: Type 'number | undefined' is not assignable to type 'number'.
!!! error TS2322:   Type 'undefined' is not assignable to type 'number'.
    }