mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-05 16:38:05 -06:00
Merge pull request #9298 from OrangeShark/new-rest-param-error
New rest parameter properties error message
This commit is contained in:
commit
3f6010cd9f
@ -18204,7 +18204,10 @@ namespace ts {
|
||||
return grammarErrorOnNode(lastDeclare, Diagnostics.A_0_modifier_cannot_be_used_with_an_import_declaration, "declare");
|
||||
}
|
||||
else if (node.kind === SyntaxKind.Parameter && (flags & NodeFlags.ParameterPropertyModifier) && isBindingPattern((<ParameterDeclaration>node).name)) {
|
||||
return grammarErrorOnNode(node, Diagnostics.A_parameter_property_may_not_be_a_binding_pattern);
|
||||
return grammarErrorOnNode(node, Diagnostics.A_parameter_property_may_not_be_declared_using_a_binding_pattern);
|
||||
}
|
||||
else if (node.kind === SyntaxKind.Parameter && (flags & NodeFlags.ParameterPropertyModifier) && (<ParameterDeclaration>node).dotDotDotToken) {
|
||||
return grammarErrorOnNode(node, Diagnostics.A_parameter_property_cannot_be_declared_using_a_rest_parameter);
|
||||
}
|
||||
if (flags & NodeFlags.Async) {
|
||||
return checkGrammarAsyncModifier(node, lastAsync);
|
||||
|
||||
@ -571,7 +571,7 @@
|
||||
"category": "Error",
|
||||
"code": 1186
|
||||
},
|
||||
"A parameter property may not be a binding pattern.": {
|
||||
"A parameter property may not be declared using a binding pattern.": {
|
||||
"category": "Error",
|
||||
"code": 1187
|
||||
},
|
||||
@ -851,6 +851,10 @@
|
||||
"category": "Error",
|
||||
"code": 1316
|
||||
},
|
||||
"A parameter property cannot be declared using a rest parameter.": {
|
||||
"category": "Error",
|
||||
"code": 1317
|
||||
},
|
||||
"Duplicate identifier '{0}'.": {
|
||||
"category": "Error",
|
||||
"code": 2300
|
||||
|
||||
@ -1178,6 +1178,7 @@ namespace ts {
|
||||
return token === SyntaxKind.OpenBracketToken
|
||||
|| token === SyntaxKind.OpenBraceToken
|
||||
|| token === SyntaxKind.AsteriskToken
|
||||
|| token === SyntaxKind.DotDotDotToken
|
||||
|| isLiteralPropertyName();
|
||||
}
|
||||
|
||||
|
||||
@ -1,13 +1,13 @@
|
||||
tests/cases/compiler/declarationEmitDestructuringParameterProperties.ts(2,17): error TS1187: A parameter property may not be a binding pattern.
|
||||
tests/cases/compiler/declarationEmitDestructuringParameterProperties.ts(8,17): error TS1187: A parameter property may not be a binding pattern.
|
||||
tests/cases/compiler/declarationEmitDestructuringParameterProperties.ts(14,17): error TS1187: A parameter property may not be a binding pattern.
|
||||
tests/cases/compiler/declarationEmitDestructuringParameterProperties.ts(2,17): error TS1187: A parameter property may not be declared using a binding pattern.
|
||||
tests/cases/compiler/declarationEmitDestructuringParameterProperties.ts(8,17): error TS1187: A parameter property may not be declared using a binding pattern.
|
||||
tests/cases/compiler/declarationEmitDestructuringParameterProperties.ts(14,17): error TS1187: A parameter property may not be declared using a binding pattern.
|
||||
|
||||
|
||||
==== tests/cases/compiler/declarationEmitDestructuringParameterProperties.ts (3 errors) ====
|
||||
class C1 {
|
||||
constructor(public [x, y, z]: string[]) {
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS1187: A parameter property may not be a binding pattern.
|
||||
!!! error TS1187: A parameter property may not be declared using a binding pattern.
|
||||
}
|
||||
}
|
||||
|
||||
@ -15,7 +15,7 @@ tests/cases/compiler/declarationEmitDestructuringParameterProperties.ts(14,17):
|
||||
class C2 {
|
||||
constructor(public [x, y, z]: TupleType1) {
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS1187: A parameter property may not be a binding pattern.
|
||||
!!! error TS1187: A parameter property may not be declared using a binding pattern.
|
||||
}
|
||||
}
|
||||
|
||||
@ -23,6 +23,6 @@ tests/cases/compiler/declarationEmitDestructuringParameterProperties.ts(14,17):
|
||||
class C3 {
|
||||
constructor(public { x, y, z }: ObjType1) {
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS1187: A parameter property may not be a binding pattern.
|
||||
!!! error TS1187: A parameter property may not be declared using a binding pattern.
|
||||
}
|
||||
}
|
||||
@ -1,5 +1,7 @@
|
||||
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(11,13): error TS2370: A rest parameter must be of an array type.
|
||||
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(13,13): error TS2370: A rest parameter must be of an array type.
|
||||
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(14,17): error TS1047: A rest parameter cannot be optional.
|
||||
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(15,16): error TS1048: A rest parameter cannot have an initializer.
|
||||
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(20,19): error TS2345: Argument of type 'boolean' is not assignable to parameter of type 'number | string'.
|
||||
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(21,7): error TS2304: Cannot find name 'array2'.
|
||||
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(22,4): error TS2345: Argument of type '[number, number, string, boolean, boolean]' is not assignable to parameter of type '[any, any, [[any]]]'.
|
||||
@ -10,12 +12,12 @@ tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(
|
||||
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(24,4): error TS2345: Argument of type '(number | string)[]' is not assignable to parameter of type 'number[]'.
|
||||
Type 'number | string' is not assignable to type 'number'.
|
||||
Type 'string' is not assignable to type 'number'.
|
||||
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(29,24): error TS1005: ',' expected.
|
||||
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(29,17): error TS1317: A parameter property cannot be declared using a rest parameter.
|
||||
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(34,22): error TS2304: Cannot find name 'E1'.
|
||||
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(34,28): error TS2304: Cannot find name 'E'.
|
||||
|
||||
|
||||
==== tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts (10 errors) ====
|
||||
==== tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts (12 errors) ====
|
||||
// If the parameter is a rest parameter, the parameter type is any[]
|
||||
// A type annotation for a rest parameter must denote an array type.
|
||||
|
||||
@ -34,7 +36,11 @@ tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(
|
||||
~~~~~~~~~~~~~~~
|
||||
!!! error TS2370: A rest parameter must be of an array type.
|
||||
function a3(...b?) { } // Error, can't be optional
|
||||
~
|
||||
!!! error TS1047: A rest parameter cannot be optional.
|
||||
function a4(...b = [1,2,3]) { } // Error, can't have initializer
|
||||
~
|
||||
!!! error TS1048: A rest parameter cannot have an initializer.
|
||||
function a5([a, b, [[c]]]) { }
|
||||
function a6([a, b, c, ...x]: number[]) { }
|
||||
|
||||
@ -63,9 +69,9 @@ tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(
|
||||
|
||||
var temp = [1, 2, 3];
|
||||
class C {
|
||||
constructor(public ...temp) { } // Error, rest parameter can't have accessibilityModifier
|
||||
~~~
|
||||
!!! error TS1005: ',' expected.
|
||||
constructor(public ...temp) { } // Error, rest parameter can't have properties
|
||||
~~~~~~~~~~~~~~
|
||||
!!! error TS1317: A parameter property cannot be declared using a rest parameter.
|
||||
}
|
||||
|
||||
// Rest parameter with generic
|
||||
|
||||
@ -27,7 +27,7 @@ a6([1, 2, "string"]); // Error, parameter type is number[]
|
||||
|
||||
var temp = [1, 2, 3];
|
||||
class C {
|
||||
constructor(public ...temp) { } // Error, rest parameter can't have accessibilityModifier
|
||||
constructor(public ...temp) { } // Error, rest parameter can't have properties
|
||||
}
|
||||
|
||||
// Rest parameter with generic
|
||||
@ -83,12 +83,13 @@ a5([1, 2]); // Error, parameter type is [any, any, [[any]]]
|
||||
a6([1, 2, "string"]); // Error, parameter type is number[]
|
||||
var temp = [1, 2, 3];
|
||||
var C = (function () {
|
||||
function C(public) {
|
||||
function C() {
|
||||
var temp = [];
|
||||
for (var _i = 1; _i < arguments.length; _i++) {
|
||||
temp[_i - 1] = arguments[_i];
|
||||
for (var _i = 0; _i < arguments.length; _i++) {
|
||||
temp[_i - 0] = arguments[_i];
|
||||
}
|
||||
} // Error, rest parameter can't have accessibilityModifier
|
||||
this.temp = temp;
|
||||
} // Error, rest parameter can't have properties
|
||||
return C;
|
||||
}());
|
||||
// Rest parameter with generic
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
tests/cases/conformance/es6/destructuring/destructuringParameterProperties1.ts(2,17): error TS1187: A parameter property may not be a binding pattern.
|
||||
tests/cases/conformance/es6/destructuring/destructuringParameterProperties1.ts(9,17): error TS1187: A parameter property may not be a binding pattern.
|
||||
tests/cases/conformance/es6/destructuring/destructuringParameterProperties1.ts(16,17): error TS1187: A parameter property may not be a binding pattern.
|
||||
tests/cases/conformance/es6/destructuring/destructuringParameterProperties1.ts(2,17): error TS1187: A parameter property may not be declared using a binding pattern.
|
||||
tests/cases/conformance/es6/destructuring/destructuringParameterProperties1.ts(9,17): error TS1187: A parameter property may not be declared using a binding pattern.
|
||||
tests/cases/conformance/es6/destructuring/destructuringParameterProperties1.ts(16,17): error TS1187: A parameter property may not be declared using a binding pattern.
|
||||
tests/cases/conformance/es6/destructuring/destructuringParameterProperties1.ts(22,26): error TS2339: Property 'x' does not exist on type 'C1'.
|
||||
tests/cases/conformance/es6/destructuring/destructuringParameterProperties1.ts(22,35): error TS2339: Property 'y' does not exist on type 'C1'.
|
||||
tests/cases/conformance/es6/destructuring/destructuringParameterProperties1.ts(22,43): error TS2339: Property 'y' does not exist on type 'C1'.
|
||||
@ -17,7 +17,7 @@ tests/cases/conformance/es6/destructuring/destructuringParameterProperties1.ts(2
|
||||
class C1 {
|
||||
constructor(public [x, y, z]: string[]) {
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS1187: A parameter property may not be a binding pattern.
|
||||
!!! error TS1187: A parameter property may not be declared using a binding pattern.
|
||||
}
|
||||
}
|
||||
|
||||
@ -26,7 +26,7 @@ tests/cases/conformance/es6/destructuring/destructuringParameterProperties1.ts(2
|
||||
class C2 {
|
||||
constructor(public [x, y, z]: TupleType1) {
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS1187: A parameter property may not be a binding pattern.
|
||||
!!! error TS1187: A parameter property may not be declared using a binding pattern.
|
||||
}
|
||||
}
|
||||
|
||||
@ -35,7 +35,7 @@ tests/cases/conformance/es6/destructuring/destructuringParameterProperties1.ts(2
|
||||
class C3 {
|
||||
constructor(public { x, y, z }: ObjType1) {
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS1187: A parameter property may not be a binding pattern.
|
||||
!!! error TS1187: A parameter property may not be declared using a binding pattern.
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
tests/cases/conformance/es6/destructuring/destructuringParameterProperties2.ts(2,36): error TS1187: A parameter property may not be a binding pattern.
|
||||
tests/cases/conformance/es6/destructuring/destructuringParameterProperties2.ts(2,36): error TS1187: A parameter property may not be declared using a binding pattern.
|
||||
tests/cases/conformance/es6/destructuring/destructuringParameterProperties2.ts(3,59): error TS2339: Property 'b' does not exist on type 'C1'.
|
||||
tests/cases/conformance/es6/destructuring/destructuringParameterProperties2.ts(3,83): error TS2339: Property 'c' does not exist on type 'C1'.
|
||||
tests/cases/conformance/es6/destructuring/destructuringParameterProperties2.ts(4,18): error TS2339: Property 'a' does not exist on type 'C1'.
|
||||
@ -14,7 +14,7 @@ tests/cases/conformance/es6/destructuring/destructuringParameterProperties2.ts(2
|
||||
class C1 {
|
||||
constructor(private k: number, private [a, b, c]: [number, string, boolean]) {
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS1187: A parameter property may not be a binding pattern.
|
||||
!!! error TS1187: A parameter property may not be declared using a binding pattern.
|
||||
if ((b === undefined && c === undefined) || (this.b === undefined && this.c === undefined)) {
|
||||
~
|
||||
!!! error TS2339: Property 'b' does not exist on type 'C1'.
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
tests/cases/conformance/es6/destructuring/destructuringParameterProperties3.ts(2,31): error TS1187: A parameter property may not be a binding pattern.
|
||||
tests/cases/conformance/es6/destructuring/destructuringParameterProperties3.ts(2,31): error TS1187: A parameter property may not be declared using a binding pattern.
|
||||
tests/cases/conformance/es6/destructuring/destructuringParameterProperties3.ts(3,59): error TS2339: Property 'b' does not exist on type 'C1<T, U, V>'.
|
||||
tests/cases/conformance/es6/destructuring/destructuringParameterProperties3.ts(3,83): error TS2339: Property 'c' does not exist on type 'C1<T, U, V>'.
|
||||
tests/cases/conformance/es6/destructuring/destructuringParameterProperties3.ts(4,18): error TS2339: Property 'a' does not exist on type 'C1<T, U, V>'.
|
||||
@ -11,7 +11,7 @@ tests/cases/conformance/es6/destructuring/destructuringParameterProperties3.ts(1
|
||||
class C1<T, U, V> {
|
||||
constructor(private k: T, private [a, b, c]: [T,U,V]) {
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS1187: A parameter property may not be a binding pattern.
|
||||
!!! error TS1187: A parameter property may not be declared using a binding pattern.
|
||||
if ((b === undefined && c === undefined) || (this.b === undefined && this.c === undefined)) {
|
||||
~
|
||||
!!! error TS2339: Property 'b' does not exist on type 'C1<T, U, V>'.
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
tests/cases/conformance/es6/destructuring/destructuringParameterProperties4.ts(3,31): error TS1187: A parameter property may not be a binding pattern.
|
||||
tests/cases/conformance/es6/destructuring/destructuringParameterProperties4.ts(3,31): error TS1187: A parameter property may not be declared using a binding pattern.
|
||||
tests/cases/conformance/es6/destructuring/destructuringParameterProperties4.ts(4,59): error TS2339: Property 'b' does not exist on type 'C1<T, U, V>'.
|
||||
tests/cases/conformance/es6/destructuring/destructuringParameterProperties4.ts(4,83): error TS2339: Property 'c' does not exist on type 'C1<T, U, V>'.
|
||||
tests/cases/conformance/es6/destructuring/destructuringParameterProperties4.ts(5,18): error TS2339: Property 'a' does not exist on type 'C1<T, U, V>'.
|
||||
@ -15,7 +15,7 @@ tests/cases/conformance/es6/destructuring/destructuringParameterProperties4.ts(2
|
||||
class C1<T, U, V> {
|
||||
constructor(private k: T, protected [a, b, c]: [T,U,V]) {
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS1187: A parameter property may not be a binding pattern.
|
||||
!!! error TS1187: A parameter property may not be declared using a binding pattern.
|
||||
if ((b === undefined && c === undefined) || (this.b === undefined && this.c === undefined)) {
|
||||
~
|
||||
!!! error TS2339: Property 'b' does not exist on type 'C1<T, U, V>'.
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
tests/cases/conformance/es6/destructuring/destructuringParameterProperties5.ts(5,17): error TS1187: A parameter property may not be a binding pattern.
|
||||
tests/cases/conformance/es6/destructuring/destructuringParameterProperties5.ts(5,17): error TS1187: A parameter property may not be declared using a binding pattern.
|
||||
tests/cases/conformance/es6/destructuring/destructuringParameterProperties5.ts(5,27): error TS2459: Type '{ x: number; y: string; z: boolean; }' has no property 'x1' and no string index signature.
|
||||
tests/cases/conformance/es6/destructuring/destructuringParameterProperties5.ts(5,31): error TS2459: Type '{ x: number; y: string; z: boolean; }' has no property 'x2' and no string index signature.
|
||||
tests/cases/conformance/es6/destructuring/destructuringParameterProperties5.ts(5,35): error TS2459: Type '{ x: number; y: string; z: boolean; }' has no property 'x3' and no string index signature.
|
||||
@ -20,7 +20,7 @@ tests/cases/conformance/es6/destructuring/destructuringParameterProperties5.ts(1
|
||||
class C1 {
|
||||
constructor(public [{ x1, x2, x3 }, y, z]: TupleType1) {
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS1187: A parameter property may not be a binding pattern.
|
||||
!!! error TS1187: A parameter property may not be declared using a binding pattern.
|
||||
~~
|
||||
!!! error TS2459: Type '{ x: number; y: string; z: boolean; }' has no property 'x1' and no string index signature.
|
||||
~~
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
tests/cases/conformance/parser/ecmascript5/RegressionTests/parser509668.ts(3,23): error TS1005: ',' expected.
|
||||
tests/cases/conformance/parser/ecmascript5/RegressionTests/parser509668.ts(3,16): error TS1317: A parameter property cannot be declared using a rest parameter.
|
||||
|
||||
|
||||
==== tests/cases/conformance/parser/ecmascript5/RegressionTests/parser509668.ts (1 errors) ====
|
||||
class Foo3 {
|
||||
// Doesn't work, but should
|
||||
constructor (public ...args: string[]) { }
|
||||
~~~
|
||||
!!! error TS1005: ',' expected.
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS1317: A parameter property cannot be declared using a rest parameter.
|
||||
}
|
||||
@ -7,11 +7,12 @@ class Foo3 {
|
||||
//// [parser509668.js]
|
||||
var Foo3 = (function () {
|
||||
// Doesn't work, but should
|
||||
function Foo3(public) {
|
||||
function Foo3() {
|
||||
var args = [];
|
||||
for (var _i = 1; _i < arguments.length; _i++) {
|
||||
args[_i - 1] = arguments[_i];
|
||||
for (var _i = 0; _i < arguments.length; _i++) {
|
||||
args[_i - 0] = arguments[_i];
|
||||
}
|
||||
this.args = args;
|
||||
}
|
||||
return Foo3;
|
||||
}());
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
tests/cases/compiler/restParamModifier2.ts(2,24): error TS1005: ',' expected.
|
||||
tests/cases/compiler/restParamModifier2.ts(2,17): error TS1317: A parameter property cannot be declared using a rest parameter.
|
||||
|
||||
|
||||
==== tests/cases/compiler/restParamModifier2.ts (1 errors) ====
|
||||
class C {
|
||||
constructor(public ...rest: string[]) {}
|
||||
~~~
|
||||
!!! error TS1005: ',' expected.
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS1317: A parameter property cannot be declared using a rest parameter.
|
||||
}
|
||||
@ -5,11 +5,12 @@ class C {
|
||||
|
||||
//// [restParamModifier2.js]
|
||||
var C = (function () {
|
||||
function C(public) {
|
||||
function C() {
|
||||
var rest = [];
|
||||
for (var _i = 1; _i < arguments.length; _i++) {
|
||||
rest[_i - 1] = arguments[_i];
|
||||
for (var _i = 0; _i < arguments.length; _i++) {
|
||||
rest[_i - 0] = arguments[_i];
|
||||
}
|
||||
this.rest = rest;
|
||||
}
|
||||
return C;
|
||||
}());
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
tests/cases/compiler/varArgConstructorMemberParameter.ts(10,25): error TS1005: ',' expected.
|
||||
tests/cases/compiler/varArgConstructorMemberParameter.ts(10,18): error TS1317: A parameter property cannot be declared using a rest parameter.
|
||||
|
||||
|
||||
==== tests/cases/compiler/varArgConstructorMemberParameter.ts (1 errors) ====
|
||||
@ -12,7 +12,7 @@ tests/cases/compiler/varArgConstructorMemberParameter.ts(10,25): error TS1005: '
|
||||
|
||||
class Foo3 {
|
||||
constructor (public ...args: string[]) { }
|
||||
~~~
|
||||
!!! error TS1005: ',' expected.
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS1317: A parameter property cannot be declared using a rest parameter.
|
||||
}
|
||||
|
||||
@ -29,11 +29,12 @@ var Foo2 = (function () {
|
||||
return Foo2;
|
||||
}());
|
||||
var Foo3 = (function () {
|
||||
function Foo3(public) {
|
||||
function Foo3() {
|
||||
var args = [];
|
||||
for (var _i = 1; _i < arguments.length; _i++) {
|
||||
args[_i - 1] = arguments[_i];
|
||||
for (var _i = 0; _i < arguments.length; _i++) {
|
||||
args[_i - 0] = arguments[_i];
|
||||
}
|
||||
this.args = args;
|
||||
}
|
||||
return Foo3;
|
||||
}());
|
||||
|
||||
@ -26,7 +26,7 @@ a6([1, 2, "string"]); // Error, parameter type is number[]
|
||||
|
||||
var temp = [1, 2, 3];
|
||||
class C {
|
||||
constructor(public ...temp) { } // Error, rest parameter can't have accessibilityModifier
|
||||
constructor(public ...temp) { } // Error, rest parameter can't have properties
|
||||
}
|
||||
|
||||
// Rest parameter with generic
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user