From 663fcdd26b34a1dd91c49e2119e2c6613936a7e7 Mon Sep 17 00:00:00 2001 From: Andrew Branch Date: Thu, 2 Sep 2021 17:24:21 -0700 Subject: [PATCH 1/2] Ignore empty binding patterns for contextual typing --- src/compiler/checker.ts | 3 ++- .../declarationEmitDestructuring4.errors.txt | 17 ----------------- ...DestructuringObjectLiteralPattern.errors.txt | 8 +------- ...estructuringObjectLiteralPattern1.errors.txt | 8 +------- .../declarationsAndAssignments.errors.txt | 8 +------- ...tyObjectBindingPatternParameter04.errors.txt | 15 --------------- .../missingAndExcessProperties.errors.txt | 8 +------- ...completionsBindingPatternAffectsInference.ts | 9 +++++++++ 8 files changed, 15 insertions(+), 61 deletions(-) delete mode 100644 tests/baselines/reference/declarationEmitDestructuring4.errors.txt delete mode 100644 tests/baselines/reference/emptyObjectBindingPatternParameter04.errors.txt create mode 100644 tests/cases/fourslash/completionsBindingPatternAffectsInference.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 186422e5a90c0..1f51fe3f4c856 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -25274,7 +25274,8 @@ namespace ts { if (result) { return result; } - if (!(contextFlags! & ContextFlags.SkipBindingPatterns) && isBindingPattern(declaration.name)) { // This is less a contextual type and more an implied shape - in some cases, this may be undesirable + if (!(contextFlags! & ContextFlags.SkipBindingPatterns) && isBindingPattern(declaration.name) && declaration.name.elements.length > 0) { + // This is less a contextual type and more an implied shape - in some cases, this may be undesirable return getTypeFromBindingPattern(declaration.name, /*includePatternInType*/ true, /*reportErrors*/ false); } } diff --git a/tests/baselines/reference/declarationEmitDestructuring4.errors.txt b/tests/baselines/reference/declarationEmitDestructuring4.errors.txt deleted file mode 100644 index 2787d5e66749f..0000000000000 --- a/tests/baselines/reference/declarationEmitDestructuring4.errors.txt +++ /dev/null @@ -1,17 +0,0 @@ -tests/cases/compiler/declarationEmitDestructuring4.ts(9,22): error TS2353: Object literal may only specify known properties, and 'x' does not exist in type '{}'. - - -==== tests/cases/compiler/declarationEmitDestructuring4.ts (1 errors) ==== - // For an array binding pattern with empty elements, - // we will not make any modification and will emit - // the similar binding pattern users' have written - function baz([]) { } - function baz1([] = [1,2,3]) { } - function baz2([[]] = [[1,2,3]]) { } - - function baz3({}) { } - function baz4({} = { x: 10 }) { } - ~ -!!! error TS2353: Object literal may only specify known properties, and 'x' does not exist in type '{}'. - - \ No newline at end of file diff --git a/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern.errors.txt b/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern.errors.txt index 63b68a6fc6b7f..9d89a96cf3c2c 100644 --- a/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern.errors.txt +++ b/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern.errors.txt @@ -1,17 +1,11 @@ -tests/cases/compiler/declarationEmitDestructuringObjectLiteralPattern.ts(1,13): error TS2353: Object literal may only specify known properties, and 'x' does not exist in type '{}'. -tests/cases/compiler/declarationEmitDestructuringObjectLiteralPattern.ts(1,19): error TS2353: Object literal may only specify known properties, and 'y' does not exist in type '{}'. tests/cases/compiler/declarationEmitDestructuringObjectLiteralPattern.ts(2,23): error TS2353: Object literal may only specify known properties, and 'y4' does not exist in type '{ x4: any; }'. tests/cases/compiler/declarationEmitDestructuringObjectLiteralPattern.ts(3,16): error TS2353: Object literal may only specify known properties, and 'x5' does not exist in type '{ y5: any; }'. tests/cases/compiler/declarationEmitDestructuringObjectLiteralPattern.ts(5,27): error TS2353: Object literal may only specify known properties, and 'y7' does not exist in type '{ x7: any; }'. tests/cases/compiler/declarationEmitDestructuringObjectLiteralPattern.ts(6,20): error TS2353: Object literal may only specify known properties, and 'x8' does not exist in type '{ y8: any; }'. -==== tests/cases/compiler/declarationEmitDestructuringObjectLiteralPattern.ts (6 errors) ==== +==== tests/cases/compiler/declarationEmitDestructuringObjectLiteralPattern.ts (4 errors) ==== var { } = { x: 5, y: "hello" }; - ~ -!!! error TS2353: Object literal may only specify known properties, and 'x' does not exist in type '{}'. - ~ -!!! error TS2353: Object literal may only specify known properties, and 'y' does not exist in type '{}'. var { x4 } = { x4: 5, y4: "hello" }; ~~ !!! error TS2353: Object literal may only specify known properties, and 'y4' does not exist in type '{ x4: any; }'. diff --git a/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern1.errors.txt b/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern1.errors.txt index bb8ec829b35f2..1bee984285cd1 100644 --- a/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern1.errors.txt +++ b/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern1.errors.txt @@ -1,17 +1,11 @@ -tests/cases/compiler/declarationEmitDestructuringObjectLiteralPattern1.ts(1,13): error TS2353: Object literal may only specify known properties, and 'x' does not exist in type '{}'. -tests/cases/compiler/declarationEmitDestructuringObjectLiteralPattern1.ts(1,19): error TS2353: Object literal may only specify known properties, and 'y' does not exist in type '{}'. tests/cases/compiler/declarationEmitDestructuringObjectLiteralPattern1.ts(2,23): error TS2353: Object literal may only specify known properties, and 'y4' does not exist in type '{ x4: any; }'. tests/cases/compiler/declarationEmitDestructuringObjectLiteralPattern1.ts(3,16): error TS2353: Object literal may only specify known properties, and 'x5' does not exist in type '{ y5: any; }'. tests/cases/compiler/declarationEmitDestructuringObjectLiteralPattern1.ts(5,27): error TS2353: Object literal may only specify known properties, and 'y7' does not exist in type '{ x7: any; }'. tests/cases/compiler/declarationEmitDestructuringObjectLiteralPattern1.ts(6,20): error TS2353: Object literal may only specify known properties, and 'x8' does not exist in type '{ y8: any; }'. -==== tests/cases/compiler/declarationEmitDestructuringObjectLiteralPattern1.ts (6 errors) ==== +==== tests/cases/compiler/declarationEmitDestructuringObjectLiteralPattern1.ts (4 errors) ==== var { } = { x: 5, y: "hello" }; - ~ -!!! error TS2353: Object literal may only specify known properties, and 'x' does not exist in type '{}'. - ~ -!!! error TS2353: Object literal may only specify known properties, and 'y' does not exist in type '{}'. var { x4 } = { x4: 5, y4: "hello" }; ~~ !!! error TS2353: Object literal may only specify known properties, and 'y4' does not exist in type '{ x4: any; }'. diff --git a/tests/baselines/reference/declarationsAndAssignments.errors.txt b/tests/baselines/reference/declarationsAndAssignments.errors.txt index 3a0b00b570ecf..550cc4b92092b 100644 --- a/tests/baselines/reference/declarationsAndAssignments.errors.txt +++ b/tests/baselines/reference/declarationsAndAssignments.errors.txt @@ -1,6 +1,4 @@ tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(5,16): error TS2493: Tuple type '[number, string]' of length '2' has no element at index '2'. -tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(22,17): error TS2353: Object literal may only specify known properties, and 'x' does not exist in type '{}'. -tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(22,23): error TS2353: Object literal may only specify known properties, and 'y' does not exist in type '{}'. tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(23,25): error TS2353: Object literal may only specify known properties, and 'y' does not exist in type '{ x: any; }'. tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(24,19): error TS2353: Object literal may only specify known properties, and 'x' does not exist in type '{ y: any; }'. tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(28,28): error TS2353: Object literal may only specify known properties, and 'y' does not exist in type '{ x: any; }'. @@ -22,7 +20,7 @@ tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(138,6): tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(138,9): error TS2322: Type 'number' is not assignable to type 'string'. -==== tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts (22 errors) ==== +==== tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts (20 errors) ==== function f0() { var [] = [1, "hello"]; var [x] = [1, "hello"]; @@ -47,10 +45,6 @@ tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(138,9): function f2() { var { } = { x: 5, y: "hello" }; // Error, no x and y in target - ~ -!!! error TS2353: Object literal may only specify known properties, and 'x' does not exist in type '{}'. - ~ -!!! error TS2353: Object literal may only specify known properties, and 'y' does not exist in type '{}'. var { x } = { x: 5, y: "hello" }; // Error, no y in target ~ !!! error TS2353: Object literal may only specify known properties, and 'y' does not exist in type '{ x: any; }'. diff --git a/tests/baselines/reference/emptyObjectBindingPatternParameter04.errors.txt b/tests/baselines/reference/emptyObjectBindingPatternParameter04.errors.txt deleted file mode 100644 index 52b69127f79c2..0000000000000 --- a/tests/baselines/reference/emptyObjectBindingPatternParameter04.errors.txt +++ /dev/null @@ -1,15 +0,0 @@ -tests/cases/conformance/es6/destructuring/emptyObjectBindingPatternParameter04.ts(1,18): error TS2353: Object literal may only specify known properties, and 'a' does not exist in type '{}'. -tests/cases/conformance/es6/destructuring/emptyObjectBindingPatternParameter04.ts(1,24): error TS2353: Object literal may only specify known properties, and 'b' does not exist in type '{}'. -tests/cases/conformance/es6/destructuring/emptyObjectBindingPatternParameter04.ts(1,32): error TS2353: Object literal may only specify known properties, and 'c' does not exist in type '{}'. - - -==== tests/cases/conformance/es6/destructuring/emptyObjectBindingPatternParameter04.ts (3 errors) ==== - function f({} = {a: 1, b: "2", c: true}) { - ~ -!!! error TS2353: Object literal may only specify known properties, and 'a' does not exist in type '{}'. - ~ -!!! error TS2353: Object literal may only specify known properties, and 'b' does not exist in type '{}'. - ~ -!!! error TS2353: Object literal may only specify known properties, and 'c' does not exist in type '{}'. - var x, y, z; - } \ No newline at end of file diff --git a/tests/baselines/reference/missingAndExcessProperties.errors.txt b/tests/baselines/reference/missingAndExcessProperties.errors.txt index 7972d770320e6..a6e949f3a8930 100644 --- a/tests/baselines/reference/missingAndExcessProperties.errors.txt +++ b/tests/baselines/reference/missingAndExcessProperties.errors.txt @@ -10,8 +10,6 @@ tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(12,8): e tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(12,11): error TS2525: Initializer provides no value for this binding element and the binding element has no default value. tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(13,18): error TS2525: Initializer provides no value for this binding element and the binding element has no default value. tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(14,8): error TS2525: Initializer provides no value for this binding element and the binding element has no default value. -tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(20,17): error TS2353: Object literal may only specify known properties, and 'x' does not exist in type '{}'. -tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(20,23): error TS2353: Object literal may only specify known properties, and 'y' does not exist in type '{}'. tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(21,25): error TS2353: Object literal may only specify known properties, and 'y' does not exist in type '{ x: any; }'. tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(22,19): error TS2353: Object literal may only specify known properties, and 'x' does not exist in type '{ y: any; }'. tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(29,14): error TS2353: Object literal may only specify known properties, and 'x' does not exist in type '{}'. @@ -20,7 +18,7 @@ tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(30,22): tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(31,16): error TS2353: Object literal may only specify known properties, and 'x' does not exist in type '{ y: number; }'. -==== tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts (20 errors) ==== +==== tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts (18 errors) ==== // Missing properties function f1() { var { x, y } = {}; @@ -69,10 +67,6 @@ tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(31,16): // Excess properties function f3() { var { } = { x: 0, y: 0 }; - ~ -!!! error TS2353: Object literal may only specify known properties, and 'x' does not exist in type '{}'. - ~ -!!! error TS2353: Object literal may only specify known properties, and 'y' does not exist in type '{}'. var { x } = { x: 0, y: 0 }; ~ !!! error TS2353: Object literal may only specify known properties, and 'y' does not exist in type '{ x: any; }'. diff --git a/tests/cases/fourslash/completionsBindingPatternAffectsInference.ts b/tests/cases/fourslash/completionsBindingPatternAffectsInference.ts new file mode 100644 index 0000000000000..2af52c4e6d3be --- /dev/null +++ b/tests/cases/fourslash/completionsBindingPatternAffectsInference.ts @@ -0,0 +1,9 @@ +/// + +//// declare function pick(keys: K[], obj: T): Pick; +//// const { /**/ } = pick(['b'], { a: 'a', b: 'b' }); + +verify.completions({ + marker: "", + exact: ["b"] +}); From c8f63928e181f4fcc36c6e8c687f3f5a7d583325 Mon Sep 17 00:00:00 2001 From: Andrew Branch Date: Fri, 3 Sep 2021 15:52:47 -0700 Subject: [PATCH 2/2] Stop looking at binding patterns for type argument inference entirely --- src/compiler/checker.ts | 4 ++-- .../declarationEmitDestructuring4.errors.txt | 17 ++++++++++++++++ ...structuringObjectLiteralPattern.errors.txt | 8 +++++++- ...tructuringObjectLiteralPattern1.errors.txt | 8 +++++++- .../declarationsAndAssignments.errors.txt | 8 +++++++- .../reference/destructuringTuple.errors.txt | 20 +------------------ .../reference/destructuringTuple.types | 10 +++++----- ...ObjectBindingPatternParameter04.errors.txt | 15 ++++++++++++++ .../missingAndExcessProperties.errors.txt | 8 +++++++- 9 files changed, 68 insertions(+), 30 deletions(-) create mode 100644 tests/baselines/reference/declarationEmitDestructuring4.errors.txt create mode 100644 tests/baselines/reference/emptyObjectBindingPatternParameter04.errors.txt diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 1f51fe3f4c856..9dff490195463 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -25274,7 +25274,7 @@ namespace ts { if (result) { return result; } - if (!(contextFlags! & ContextFlags.SkipBindingPatterns) && isBindingPattern(declaration.name) && declaration.name.elements.length > 0) { + if (!(contextFlags! & ContextFlags.SkipBindingPatterns) && isBindingPattern(declaration.name)) { // This is less a contextual type and more an implied shape - in some cases, this may be undesirable return getTypeFromBindingPattern(declaration.name, /*includePatternInType*/ true, /*reportErrors*/ false); } @@ -28574,7 +28574,7 @@ namespace ts { // 'let f: (x: string) => number = wrap(s => s.length)', we infer from the declared type of 'f' to the // return type of 'wrap'. if (node.kind !== SyntaxKind.Decorator) { - const contextualType = getContextualType(node, every(signature.typeParameters, p => !!getDefaultFromTypeParameter(p)) ? ContextFlags.SkipBindingPatterns : ContextFlags.None); + const contextualType = getContextualType(node, ContextFlags.SkipBindingPatterns); if (contextualType) { // We clone the inference context to avoid disturbing a resolution in progress for an // outer call expression. Effectively we just want a snapshot of whatever has been diff --git a/tests/baselines/reference/declarationEmitDestructuring4.errors.txt b/tests/baselines/reference/declarationEmitDestructuring4.errors.txt new file mode 100644 index 0000000000000..2787d5e66749f --- /dev/null +++ b/tests/baselines/reference/declarationEmitDestructuring4.errors.txt @@ -0,0 +1,17 @@ +tests/cases/compiler/declarationEmitDestructuring4.ts(9,22): error TS2353: Object literal may only specify known properties, and 'x' does not exist in type '{}'. + + +==== tests/cases/compiler/declarationEmitDestructuring4.ts (1 errors) ==== + // For an array binding pattern with empty elements, + // we will not make any modification and will emit + // the similar binding pattern users' have written + function baz([]) { } + function baz1([] = [1,2,3]) { } + function baz2([[]] = [[1,2,3]]) { } + + function baz3({}) { } + function baz4({} = { x: 10 }) { } + ~ +!!! error TS2353: Object literal may only specify known properties, and 'x' does not exist in type '{}'. + + \ No newline at end of file diff --git a/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern.errors.txt b/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern.errors.txt index 9d89a96cf3c2c..63b68a6fc6b7f 100644 --- a/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern.errors.txt +++ b/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern.errors.txt @@ -1,11 +1,17 @@ +tests/cases/compiler/declarationEmitDestructuringObjectLiteralPattern.ts(1,13): error TS2353: Object literal may only specify known properties, and 'x' does not exist in type '{}'. +tests/cases/compiler/declarationEmitDestructuringObjectLiteralPattern.ts(1,19): error TS2353: Object literal may only specify known properties, and 'y' does not exist in type '{}'. tests/cases/compiler/declarationEmitDestructuringObjectLiteralPattern.ts(2,23): error TS2353: Object literal may only specify known properties, and 'y4' does not exist in type '{ x4: any; }'. tests/cases/compiler/declarationEmitDestructuringObjectLiteralPattern.ts(3,16): error TS2353: Object literal may only specify known properties, and 'x5' does not exist in type '{ y5: any; }'. tests/cases/compiler/declarationEmitDestructuringObjectLiteralPattern.ts(5,27): error TS2353: Object literal may only specify known properties, and 'y7' does not exist in type '{ x7: any; }'. tests/cases/compiler/declarationEmitDestructuringObjectLiteralPattern.ts(6,20): error TS2353: Object literal may only specify known properties, and 'x8' does not exist in type '{ y8: any; }'. -==== tests/cases/compiler/declarationEmitDestructuringObjectLiteralPattern.ts (4 errors) ==== +==== tests/cases/compiler/declarationEmitDestructuringObjectLiteralPattern.ts (6 errors) ==== var { } = { x: 5, y: "hello" }; + ~ +!!! error TS2353: Object literal may only specify known properties, and 'x' does not exist in type '{}'. + ~ +!!! error TS2353: Object literal may only specify known properties, and 'y' does not exist in type '{}'. var { x4 } = { x4: 5, y4: "hello" }; ~~ !!! error TS2353: Object literal may only specify known properties, and 'y4' does not exist in type '{ x4: any; }'. diff --git a/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern1.errors.txt b/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern1.errors.txt index 1bee984285cd1..bb8ec829b35f2 100644 --- a/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern1.errors.txt +++ b/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern1.errors.txt @@ -1,11 +1,17 @@ +tests/cases/compiler/declarationEmitDestructuringObjectLiteralPattern1.ts(1,13): error TS2353: Object literal may only specify known properties, and 'x' does not exist in type '{}'. +tests/cases/compiler/declarationEmitDestructuringObjectLiteralPattern1.ts(1,19): error TS2353: Object literal may only specify known properties, and 'y' does not exist in type '{}'. tests/cases/compiler/declarationEmitDestructuringObjectLiteralPattern1.ts(2,23): error TS2353: Object literal may only specify known properties, and 'y4' does not exist in type '{ x4: any; }'. tests/cases/compiler/declarationEmitDestructuringObjectLiteralPattern1.ts(3,16): error TS2353: Object literal may only specify known properties, and 'x5' does not exist in type '{ y5: any; }'. tests/cases/compiler/declarationEmitDestructuringObjectLiteralPattern1.ts(5,27): error TS2353: Object literal may only specify known properties, and 'y7' does not exist in type '{ x7: any; }'. tests/cases/compiler/declarationEmitDestructuringObjectLiteralPattern1.ts(6,20): error TS2353: Object literal may only specify known properties, and 'x8' does not exist in type '{ y8: any; }'. -==== tests/cases/compiler/declarationEmitDestructuringObjectLiteralPattern1.ts (4 errors) ==== +==== tests/cases/compiler/declarationEmitDestructuringObjectLiteralPattern1.ts (6 errors) ==== var { } = { x: 5, y: "hello" }; + ~ +!!! error TS2353: Object literal may only specify known properties, and 'x' does not exist in type '{}'. + ~ +!!! error TS2353: Object literal may only specify known properties, and 'y' does not exist in type '{}'. var { x4 } = { x4: 5, y4: "hello" }; ~~ !!! error TS2353: Object literal may only specify known properties, and 'y4' does not exist in type '{ x4: any; }'. diff --git a/tests/baselines/reference/declarationsAndAssignments.errors.txt b/tests/baselines/reference/declarationsAndAssignments.errors.txt index 550cc4b92092b..3a0b00b570ecf 100644 --- a/tests/baselines/reference/declarationsAndAssignments.errors.txt +++ b/tests/baselines/reference/declarationsAndAssignments.errors.txt @@ -1,4 +1,6 @@ tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(5,16): error TS2493: Tuple type '[number, string]' of length '2' has no element at index '2'. +tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(22,17): error TS2353: Object literal may only specify known properties, and 'x' does not exist in type '{}'. +tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(22,23): error TS2353: Object literal may only specify known properties, and 'y' does not exist in type '{}'. tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(23,25): error TS2353: Object literal may only specify known properties, and 'y' does not exist in type '{ x: any; }'. tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(24,19): error TS2353: Object literal may only specify known properties, and 'x' does not exist in type '{ y: any; }'. tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(28,28): error TS2353: Object literal may only specify known properties, and 'y' does not exist in type '{ x: any; }'. @@ -20,7 +22,7 @@ tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(138,6): tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(138,9): error TS2322: Type 'number' is not assignable to type 'string'. -==== tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts (20 errors) ==== +==== tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts (22 errors) ==== function f0() { var [] = [1, "hello"]; var [x] = [1, "hello"]; @@ -45,6 +47,10 @@ tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(138,9): function f2() { var { } = { x: 5, y: "hello" }; // Error, no x and y in target + ~ +!!! error TS2353: Object literal may only specify known properties, and 'x' does not exist in type '{}'. + ~ +!!! error TS2353: Object literal may only specify known properties, and 'y' does not exist in type '{}'. var { x } = { x: 5, y: "hello" }; // Error, no y in target ~ !!! error TS2353: Object literal may only specify known properties, and 'y' does not exist in type '{ x: any; }'. diff --git a/tests/baselines/reference/destructuringTuple.errors.txt b/tests/baselines/reference/destructuringTuple.errors.txt index 3b074480a865b..2471c24dc9682 100644 --- a/tests/baselines/reference/destructuringTuple.errors.txt +++ b/tests/baselines/reference/destructuringTuple.errors.txt @@ -1,10 +1,3 @@ -tests/cases/compiler/destructuringTuple.ts(11,7): error TS2461: Type 'number' is not an array type. -tests/cases/compiler/destructuringTuple.ts(11,48): error TS2769: No overload matches this call. - Overload 1 of 3, '(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: number[]) => number, initialValue: number): number', gave the following error. - Type 'never[]' is not assignable to type 'number'. - Overload 2 of 3, '(callbackfn: (previousValue: [], currentValue: number, currentIndex: number, array: number[]) => [], initialValue: []): []', gave the following error. - Type 'never[]' is not assignable to type '[]'. - Target allows only 0 element(s) but source may have more. tests/cases/compiler/destructuringTuple.ts(11,60): error TS2769: No overload matches this call. Overload 1 of 2, '(...items: ConcatArray[]): never[]', gave the following error. Argument of type 'number' is not assignable to parameter of type 'ConcatArray'. @@ -12,7 +5,7 @@ tests/cases/compiler/destructuringTuple.ts(11,60): error TS2769: No overload mat Argument of type 'number' is not assignable to parameter of type 'ConcatArray'. -==== tests/cases/compiler/destructuringTuple.ts (3 errors) ==== +==== tests/cases/compiler/destructuringTuple.ts (1 errors) ==== declare var tuple: [boolean, number, ...string[]]; const [a, b, c, ...rest] = tuple; @@ -24,17 +17,6 @@ tests/cases/compiler/destructuringTuple.ts(11,60): error TS2769: No overload mat // Repros from #32140 const [oops1] = [1, 2, 3].reduce((accu, el) => accu.concat(el), []); - ~~~~~~~ -!!! error TS2461: Type 'number' is not an array type. - ~~~~~~~~~~~~~~~ -!!! error TS2769: No overload matches this call. -!!! error TS2769: Overload 1 of 3, '(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: number[]) => number, initialValue: number): number', gave the following error. -!!! error TS2769: Type 'never[]' is not assignable to type 'number'. -!!! error TS2769: Overload 2 of 3, '(callbackfn: (previousValue: [], currentValue: number, currentIndex: number, array: number[]) => [], initialValue: []): []', gave the following error. -!!! error TS2769: Type 'never[]' is not assignable to type '[]'. -!!! error TS2769: Target allows only 0 element(s) but source may have more. -!!! related TS6502 /.ts/lib.es5.d.ts:1412:24: The expected type comes from the return type of this signature. -!!! related TS6502 /.ts/lib.es5.d.ts:1418:27: The expected type comes from the return type of this signature. ~~ !!! error TS2769: No overload matches this call. !!! error TS2769: Overload 1 of 2, '(...items: ConcatArray[]): never[]', gave the following error. diff --git a/tests/baselines/reference/destructuringTuple.types b/tests/baselines/reference/destructuringTuple.types index 0227d82572ddc..e4fc79d71f688 100644 --- a/tests/baselines/reference/destructuringTuple.types +++ b/tests/baselines/reference/destructuringTuple.types @@ -23,20 +23,20 @@ declare var receiver: typeof tuple; // Repros from #32140 const [oops1] = [1, 2, 3].reduce((accu, el) => accu.concat(el), []); ->oops1 : any ->[1, 2, 3].reduce((accu, el) => accu.concat(el), []) : number +>oops1 : never +>[1, 2, 3].reduce((accu, el) => accu.concat(el), []) : never[] >[1, 2, 3].reduce : { (callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: number[]) => number): number; (callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: number[]) => number, initialValue: number): number; (callbackfn: (previousValue: U, currentValue: number, currentIndex: number, array: number[]) => U, initialValue: U): U; } >[1, 2, 3] : number[] >1 : 1 >2 : 2 >3 : 3 >reduce : { (callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: number[]) => number): number; (callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: number[]) => number, initialValue: number): number; (callbackfn: (previousValue: U, currentValue: number, currentIndex: number, array: number[]) => U, initialValue: U): U; } ->(accu, el) => accu.concat(el) : (accu: [], el: number) => never[] ->accu : [] +>(accu, el) => accu.concat(el) : (accu: never[], el: number) => never[] +>accu : never[] >el : number >accu.concat(el) : never[] >accu.concat : { (...items: ConcatArray[]): never[]; (...items: ConcatArray[]): never[]; } ->accu : [] +>accu : never[] >concat : { (...items: ConcatArray[]): never[]; (...items: ConcatArray[]): never[]; } >el : number >[] : never[] diff --git a/tests/baselines/reference/emptyObjectBindingPatternParameter04.errors.txt b/tests/baselines/reference/emptyObjectBindingPatternParameter04.errors.txt new file mode 100644 index 0000000000000..52b69127f79c2 --- /dev/null +++ b/tests/baselines/reference/emptyObjectBindingPatternParameter04.errors.txt @@ -0,0 +1,15 @@ +tests/cases/conformance/es6/destructuring/emptyObjectBindingPatternParameter04.ts(1,18): error TS2353: Object literal may only specify known properties, and 'a' does not exist in type '{}'. +tests/cases/conformance/es6/destructuring/emptyObjectBindingPatternParameter04.ts(1,24): error TS2353: Object literal may only specify known properties, and 'b' does not exist in type '{}'. +tests/cases/conformance/es6/destructuring/emptyObjectBindingPatternParameter04.ts(1,32): error TS2353: Object literal may only specify known properties, and 'c' does not exist in type '{}'. + + +==== tests/cases/conformance/es6/destructuring/emptyObjectBindingPatternParameter04.ts (3 errors) ==== + function f({} = {a: 1, b: "2", c: true}) { + ~ +!!! error TS2353: Object literal may only specify known properties, and 'a' does not exist in type '{}'. + ~ +!!! error TS2353: Object literal may only specify known properties, and 'b' does not exist in type '{}'. + ~ +!!! error TS2353: Object literal may only specify known properties, and 'c' does not exist in type '{}'. + var x, y, z; + } \ No newline at end of file diff --git a/tests/baselines/reference/missingAndExcessProperties.errors.txt b/tests/baselines/reference/missingAndExcessProperties.errors.txt index a6e949f3a8930..7972d770320e6 100644 --- a/tests/baselines/reference/missingAndExcessProperties.errors.txt +++ b/tests/baselines/reference/missingAndExcessProperties.errors.txt @@ -10,6 +10,8 @@ tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(12,8): e tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(12,11): error TS2525: Initializer provides no value for this binding element and the binding element has no default value. tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(13,18): error TS2525: Initializer provides no value for this binding element and the binding element has no default value. tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(14,8): error TS2525: Initializer provides no value for this binding element and the binding element has no default value. +tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(20,17): error TS2353: Object literal may only specify known properties, and 'x' does not exist in type '{}'. +tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(20,23): error TS2353: Object literal may only specify known properties, and 'y' does not exist in type '{}'. tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(21,25): error TS2353: Object literal may only specify known properties, and 'y' does not exist in type '{ x: any; }'. tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(22,19): error TS2353: Object literal may only specify known properties, and 'x' does not exist in type '{ y: any; }'. tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(29,14): error TS2353: Object literal may only specify known properties, and 'x' does not exist in type '{}'. @@ -18,7 +20,7 @@ tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(30,22): tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(31,16): error TS2353: Object literal may only specify known properties, and 'x' does not exist in type '{ y: number; }'. -==== tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts (18 errors) ==== +==== tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts (20 errors) ==== // Missing properties function f1() { var { x, y } = {}; @@ -67,6 +69,10 @@ tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(31,16): // Excess properties function f3() { var { } = { x: 0, y: 0 }; + ~ +!!! error TS2353: Object literal may only specify known properties, and 'x' does not exist in type '{}'. + ~ +!!! error TS2353: Object literal may only specify known properties, and 'y' does not exist in type '{}'. var { x } = { x: 0, y: 0 }; ~ !!! error TS2353: Object literal may only specify known properties, and 'y' does not exist in type '{ x: any; }'.