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 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191
|
=== tests/cases/conformance/pedantic/noUncheckedIndexedAccessDestructuring.ts ===
declare const strArray: string[];
>strArray : Symbol(strArray, Decl(noUncheckedIndexedAccessDestructuring.ts, 0, 13))
declare const strStrTuple: [string, string];
>strStrTuple : Symbol(strStrTuple, Decl(noUncheckedIndexedAccessDestructuring.ts, 1, 13))
// Declaration forms for array destructuring
// Destructuring from a simple array -> include undefined
const [s1] = strArray;
>s1 : Symbol(s1, Decl(noUncheckedIndexedAccessDestructuring.ts, 6, 7))
>strArray : Symbol(strArray, Decl(noUncheckedIndexedAccessDestructuring.ts, 0, 13))
s1.toString(); // Should error, s1 possibly undefined
>s1.toString : Symbol(String.toString, Decl(lib.es5.d.ts, --, --))
>s1 : Symbol(s1, Decl(noUncheckedIndexedAccessDestructuring.ts, 6, 7))
>toString : Symbol(String.toString, Decl(lib.es5.d.ts, --, --))
// Destructuring a rest element -> do not include undefined
const [...s2] = strArray;
>s2 : Symbol(s2, Decl(noUncheckedIndexedAccessDestructuring.ts, 10, 7))
>strArray : Symbol(strArray, Decl(noUncheckedIndexedAccessDestructuring.ts, 0, 13))
s2.push(undefined); // Should error, 'undefined' not part of s2's element type
>s2.push : Symbol(Array.push, Decl(lib.es5.d.ts, --, --))
>s2 : Symbol(s2, Decl(noUncheckedIndexedAccessDestructuring.ts, 10, 7))
>push : Symbol(Array.push, Decl(lib.es5.d.ts, --, --))
>undefined : Symbol(undefined)
// Destructuring a rest element -> do not include undefined
const [, , ...s3] = strArray;
>s3 : Symbol(s3, Decl(noUncheckedIndexedAccessDestructuring.ts, 14, 10))
>strArray : Symbol(strArray, Decl(noUncheckedIndexedAccessDestructuring.ts, 0, 13))
s3.push(undefined); // Should error, 'undefined' not part of s2's element type
>s3.push : Symbol(Array.push, Decl(lib.es5.d.ts, --, --))
>s3 : Symbol(s3, Decl(noUncheckedIndexedAccessDestructuring.ts, 14, 10))
>push : Symbol(Array.push, Decl(lib.es5.d.ts, --, --))
>undefined : Symbol(undefined)
// Declaration forms for object destructuring
declare const strMap: { [s: string]: string };
>strMap : Symbol(strMap, Decl(noUncheckedIndexedAccessDestructuring.ts, 19, 13))
>s : Symbol(s, Decl(noUncheckedIndexedAccessDestructuring.ts, 19, 25))
const { t1 } = strMap;
>t1 : Symbol(t1, Decl(noUncheckedIndexedAccessDestructuring.ts, 21, 7))
>strMap : Symbol(strMap, Decl(noUncheckedIndexedAccessDestructuring.ts, 19, 13))
t1.toString(); // Should error, t1 possibly undefined
>t1.toString : Symbol(String.toString, Decl(lib.es5.d.ts, --, --))
>t1 : Symbol(t1, Decl(noUncheckedIndexedAccessDestructuring.ts, 21, 7))
>toString : Symbol(String.toString, Decl(lib.es5.d.ts, --, --))
const { ...t2 } = strMap;
>t2 : Symbol(t2, Decl(noUncheckedIndexedAccessDestructuring.ts, 24, 7))
>strMap : Symbol(strMap, Decl(noUncheckedIndexedAccessDestructuring.ts, 19, 13))
t2.z.toString(); // Should error
>t2.z.toString : Symbol(String.toString, Decl(lib.es5.d.ts, --, --))
>t2 : Symbol(t2, Decl(noUncheckedIndexedAccessDestructuring.ts, 24, 7))
>toString : Symbol(String.toString, Decl(lib.es5.d.ts, --, --))
// Test intersections with declared properties
declare const numMapPoint: { x: number, y: number} & { [s: string]: number };
>numMapPoint : Symbol(numMapPoint, Decl(noUncheckedIndexedAccessDestructuring.ts, 28, 13))
>x : Symbol(x, Decl(noUncheckedIndexedAccessDestructuring.ts, 28, 28))
>y : Symbol(y, Decl(noUncheckedIndexedAccessDestructuring.ts, 28, 39))
>s : Symbol(s, Decl(noUncheckedIndexedAccessDestructuring.ts, 28, 56))
{
const { x, y, z } = numMapPoint;
>x : Symbol(x, Decl(noUncheckedIndexedAccessDestructuring.ts, 30, 11))
>y : Symbol(y, Decl(noUncheckedIndexedAccessDestructuring.ts, 30, 14))
>z : Symbol(z, Decl(noUncheckedIndexedAccessDestructuring.ts, 30, 17))
>numMapPoint : Symbol(numMapPoint, Decl(noUncheckedIndexedAccessDestructuring.ts, 28, 13))
x.toFixed(); // Should OK
>x.toFixed : Symbol(Number.toFixed, Decl(lib.es5.d.ts, --, --))
>x : Symbol(x, Decl(noUncheckedIndexedAccessDestructuring.ts, 30, 11))
>toFixed : Symbol(Number.toFixed, Decl(lib.es5.d.ts, --, --))
y.toFixed(); // Should OK
>y.toFixed : Symbol(Number.toFixed, Decl(lib.es5.d.ts, --, --))
>y : Symbol(y, Decl(noUncheckedIndexedAccessDestructuring.ts, 30, 14))
>toFixed : Symbol(Number.toFixed, Decl(lib.es5.d.ts, --, --))
z.toFixed(); // Should error
>z.toFixed : Symbol(Number.toFixed, Decl(lib.es5.d.ts, --, --))
>z : Symbol(z, Decl(noUncheckedIndexedAccessDestructuring.ts, 30, 17))
>toFixed : Symbol(Number.toFixed, Decl(lib.es5.d.ts, --, --))
}
{
const { x, ...q } = numMapPoint;
>x : Symbol(x, Decl(noUncheckedIndexedAccessDestructuring.ts, 37, 11))
>q : Symbol(q, Decl(noUncheckedIndexedAccessDestructuring.ts, 37, 14))
>numMapPoint : Symbol(numMapPoint, Decl(noUncheckedIndexedAccessDestructuring.ts, 28, 13))
x.toFixed(); // Should OK
>x.toFixed : Symbol(Number.toFixed, Decl(lib.es5.d.ts, --, --))
>x : Symbol(x, Decl(noUncheckedIndexedAccessDestructuring.ts, 37, 11))
>toFixed : Symbol(Number.toFixed, Decl(lib.es5.d.ts, --, --))
q.y.toFixed(); // Should OK
>q.y.toFixed : Symbol(Number.toFixed, Decl(lib.es5.d.ts, --, --))
>q.y : Symbol(y, Decl(noUncheckedIndexedAccessDestructuring.ts, 28, 39))
>q : Symbol(q, Decl(noUncheckedIndexedAccessDestructuring.ts, 37, 14))
>y : Symbol(y, Decl(noUncheckedIndexedAccessDestructuring.ts, 28, 39))
>toFixed : Symbol(Number.toFixed, Decl(lib.es5.d.ts, --, --))
q.z.toFixed(); // Should error
>q.z.toFixed : Symbol(Number.toFixed, Decl(lib.es5.d.ts, --, --))
>q : Symbol(q, Decl(noUncheckedIndexedAccessDestructuring.ts, 37, 14))
>toFixed : Symbol(Number.toFixed, Decl(lib.es5.d.ts, --, --))
}
{
const { x, ...q } = numMapPoint;
>x : Symbol(x, Decl(noUncheckedIndexedAccessDestructuring.ts, 44, 11))
>q : Symbol(q, Decl(noUncheckedIndexedAccessDestructuring.ts, 44, 14))
>numMapPoint : Symbol(numMapPoint, Decl(noUncheckedIndexedAccessDestructuring.ts, 28, 13))
x.
>x. toFixed : Symbol(Number.toFixed, Decl(lib.es5.d.ts, --, --))
>x : Symbol(x, Decl(noUncheckedIndexedAccessDestructuring.ts, 44, 11))
toFixed(); // Should OK
>toFixed : Symbol(Number.toFixed, Decl(lib.es5.d.ts, --, --))
q.
>q. y.toFixed : Symbol(Number.toFixed, Decl(lib.es5.d.ts, --, --))
>q. y : Symbol(y, Decl(noUncheckedIndexedAccessDestructuring.ts, 28, 39))
>q : Symbol(q, Decl(noUncheckedIndexedAccessDestructuring.ts, 44, 14))
y.toFixed(); // Should OK
>y : Symbol(y, Decl(noUncheckedIndexedAccessDestructuring.ts, 28, 39))
>toFixed : Symbol(Number.toFixed, Decl(lib.es5.d.ts, --, --))
q.
>q. z.toFixed : Symbol(Number.toFixed, Decl(lib.es5.d.ts, --, --))
>q : Symbol(q, Decl(noUncheckedIndexedAccessDestructuring.ts, 44, 14))
z.toFixed(); // Should error
>toFixed : Symbol(Number.toFixed, Decl(lib.es5.d.ts, --, --))
}
declare let target_string: string;
>target_string : Symbol(target_string, Decl(noUncheckedIndexedAccessDestructuring.ts, 56, 11))
declare let target_string_undef: string | undefined;
>target_string_undef : Symbol(target_string_undef, Decl(noUncheckedIndexedAccessDestructuring.ts, 57, 11))
declare let target_string_arr: string[];
>target_string_arr : Symbol(target_string_arr, Decl(noUncheckedIndexedAccessDestructuring.ts, 58, 11))
// Assignment forms
[target_string] = strArray; // Should error
>target_string : Symbol(target_string, Decl(noUncheckedIndexedAccessDestructuring.ts, 56, 11))
>strArray : Symbol(strArray, Decl(noUncheckedIndexedAccessDestructuring.ts, 0, 13))
[target_string_undef] = strArray; // Should OK
>target_string_undef : Symbol(target_string_undef, Decl(noUncheckedIndexedAccessDestructuring.ts, 57, 11))
>strArray : Symbol(strArray, Decl(noUncheckedIndexedAccessDestructuring.ts, 0, 13))
[,,, ...target_string_arr] = strArray; // Should OK
>target_string_arr : Symbol(target_string_arr, Decl(noUncheckedIndexedAccessDestructuring.ts, 58, 11))
>strArray : Symbol(strArray, Decl(noUncheckedIndexedAccessDestructuring.ts, 0, 13))
{
let x: number, y: number, z: number | undefined;
>x : Symbol(x, Decl(noUncheckedIndexedAccessDestructuring.ts, 66, 7))
>y : Symbol(y, Decl(noUncheckedIndexedAccessDestructuring.ts, 66, 18))
>z : Symbol(z, Decl(noUncheckedIndexedAccessDestructuring.ts, 66, 29))
({ x, y, z } = numMapPoint); // Should OK
>x : Symbol(x, Decl(noUncheckedIndexedAccessDestructuring.ts, 67, 6))
>y : Symbol(y, Decl(noUncheckedIndexedAccessDestructuring.ts, 67, 9))
>z : Symbol(z, Decl(noUncheckedIndexedAccessDestructuring.ts, 67, 12))
>numMapPoint : Symbol(numMapPoint, Decl(noUncheckedIndexedAccessDestructuring.ts, 28, 13))
let q: number;
>q : Symbol(q, Decl(noUncheckedIndexedAccessDestructuring.ts, 69, 7))
({ q } = numMapPoint); // Should error
>q : Symbol(q, Decl(noUncheckedIndexedAccessDestructuring.ts, 70, 6))
>numMapPoint : Symbol(numMapPoint, Decl(noUncheckedIndexedAccessDestructuring.ts, 28, 13))
}
|