diff --git a/tests/baselines/reference/destructuringControlFlow.errors.txt b/tests/baselines/reference/destructuringControlFlow.errors.txt index 2bc85fdd63..e83a76942f 100644 --- a/tests/baselines/reference/destructuringControlFlow.errors.txt +++ b/tests/baselines/reference/destructuringControlFlow.errors.txt @@ -1,9 +1,10 @@ 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 TS2532: Object is possibly 'undefined'. -==== tests/cases/conformance/es6/destructuring/destructuringControlFlow.ts (3 errors) ==== +==== tests/cases/conformance/es6/destructuring/destructuringControlFlow.ts (4 errors) ==== function f1(obj: { a?: string }) { if (obj.a) { obj = {}; @@ -44,4 +45,12 @@ tests/cases/conformance/es6/destructuring/destructuringControlFlow.ts(33,9): err ~~~~~~~~ !!! 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 TS2532: Object is possibly 'undefined'. \ No newline at end of file diff --git a/tests/baselines/reference/destructuringControlFlow.js b/tests/baselines/reference/destructuringControlFlow.js index 2d02fb5a40..f3b5a8e0dd 100644 --- a/tests/baselines/reference/destructuringControlFlow.js +++ b/tests/baselines/reference/destructuringControlFlow.js @@ -33,6 +33,12 @@ function f4() { ({ ["x"]: x } = 0); // Error ({ ["x" + ""]: x } = 0); // Errpr } + +// Repro from #31770 + +type KeyValue = [string, string?]; +let [key, value]: KeyValue = ["foo"]; +value.toUpperCase(); // Error //// [destructuringControlFlow.js] @@ -69,3 +75,5 @@ function f4() { (x = 0["x"]); // Error (_a = "x" + "", x = 0[_a]); // Errpr } +var _a = ["foo"], key = _a[0], value = _a[1]; +value.toUpperCase(); // Error diff --git a/tests/baselines/reference/destructuringControlFlow.symbols b/tests/baselines/reference/destructuringControlFlow.symbols index 75cbfcdb48..5e3fa6a365 100644 --- a/tests/baselines/reference/destructuringControlFlow.symbols +++ b/tests/baselines/reference/destructuringControlFlow.symbols @@ -122,3 +122,16 @@ function f4() { >x : Symbol(x, Decl(destructuringControlFlow.ts, 29, 7)) } +// Repro from #31770 + +type KeyValue = [string, string?]; +>KeyValue : Symbol(KeyValue, Decl(destructuringControlFlow.ts, 33, 1)) + +let [key, value]: KeyValue = ["foo"]; +>key : Symbol(key, Decl(destructuringControlFlow.ts, 38, 5)) +>value : Symbol(value, Decl(destructuringControlFlow.ts, 38, 9)) +>KeyValue : Symbol(KeyValue, Decl(destructuringControlFlow.ts, 33, 1)) + +value.toUpperCase(); // Error +>value : Symbol(value, Decl(destructuringControlFlow.ts, 38, 9)) + diff --git a/tests/baselines/reference/destructuringControlFlow.types b/tests/baselines/reference/destructuringControlFlow.types index b831d11674..347aae32c1 100644 --- a/tests/baselines/reference/destructuringControlFlow.types +++ b/tests/baselines/reference/destructuringControlFlow.types @@ -158,3 +158,20 @@ function f4() { >0 : 0 } +// Repro from #31770 + +type KeyValue = [string, string?]; +>KeyValue : [string, (string | undefined)?] + +let [key, value]: KeyValue = ["foo"]; +>key : string +>value : string | undefined +>["foo"] : [string] +>"foo" : "foo" + +value.toUpperCase(); // Error +>value.toUpperCase() : any +>value.toUpperCase : any +>value : undefined +>toUpperCase : any +