From 307a9b66afb593e02af5100412d3aac4191610b6 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sun, 16 Dec 2018 07:23:28 -0800 Subject: [PATCH] Add tests --- .../destructuring/destructuringControlFlow.ts | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 tests/cases/conformance/es6/destructuring/destructuringControlFlow.ts diff --git a/tests/cases/conformance/es6/destructuring/destructuringControlFlow.ts b/tests/cases/conformance/es6/destructuring/destructuringControlFlow.ts new file mode 100644 index 00000000000..033f2bdb75e --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/destructuringControlFlow.ts @@ -0,0 +1,36 @@ +// @strict: true + +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 + ({ ["x"]: x } = 0); // Error + ({ ["x" + ""]: x } = 0); // Errpr +}