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
|
tests/cases/conformance/es6/destructuring/destructuringControlFlow.ts(31,8): error TS2339: Property 'x' does not exist on type 'Number'.
tests/cases/conformance/es6/destructuring/destructuringControlFlow.ts(32,9): error TS2339: Property 'x' does not exist on type 'Number'.
tests/cases/conformance/es6/destructuring/destructuringControlFlow.ts(33,9): error TS2537: Type 'Number' has no matching index signature for type 'string'.
tests/cases/conformance/es6/destructuring/destructuringControlFlow.ts(40,1): error TS18048: 'value' is possibly 'undefined'.
==== tests/cases/conformance/es6/destructuring/destructuringControlFlow.ts (4 errors) ====
function f1(obj: { a?: string }) {
if (obj.a) {
obj = {};
let a1 = obj["a"]; // string | undefined
let a2 = obj.a; // string | undefined
}
}
function f2(obj: [number, string] | null[]) {
let a0 = obj[0]; // number | null
let a1 = obj[1]; // string | null
let [b0, b1] = obj;
([a0, a1] = obj);
if (obj[0] && obj[1]) {
let c0 = obj[0]; // number
let c1 = obj[1]; // string
let [d0, d1] = obj;
([c0, c1] = obj);
}
}
function f3(obj: { a?: number, b?: string }) {
if (obj.a && obj.b) {
let { a, b } = obj; // number, string
({ a, b } = obj);
}
}
function f4() {
let x: boolean;
({ x } = 0); // Error
~
!!! error TS2339: Property 'x' does not exist on type 'Number'.
({ ["x"]: x } = 0); // Error
~~~
!!! error TS2339: Property 'x' does not exist on type 'Number'.
({ ["x" + ""]: x } = 0); // Errpr
~~~~~~~~
!!! error TS2537: Type 'Number' has no matching index signature for type 'string'.
}
// Repro from #31770
type KeyValue = [string, string?];
let [key, value]: KeyValue = ["foo"];
value.toUpperCase(); // Error
~~~~~
!!! error TS18048: 'value' is possibly 'undefined'.
|