mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-07 05:41:22 -06:00
make it work with AssignmentRestElement
This commit is contained in:
parent
090326be6a
commit
51b752bbda
@ -21066,7 +21066,7 @@ namespace ts {
|
||||
else {
|
||||
checkGrammarForDisallowedTrailingComma(node.elements, Diagnostics.A_rest_parameter_or_binding_pattern_may_not_have_a_trailing_comma);
|
||||
const type = isTupleType(sourceType) ?
|
||||
getArrayLiteralType((sourceType.typeArguments || emptyArray).slice(elementIndex, getTypeReferenceArity(sourceType))) :
|
||||
sliceTupleType(sourceType, elementIndex) :
|
||||
createArrayType(elementType);
|
||||
return checkDestructuringAssignment(restExpression, type, checkMode);
|
||||
}
|
||||
|
||||
@ -2,8 +2,13 @@
|
||||
declare var tuple: [boolean, number, ...string[]];
|
||||
|
||||
const [a, b, c, ...rest] = tuple;
|
||||
|
||||
declare var receiver: typeof tuple;
|
||||
|
||||
[...receiver] = tuple;
|
||||
|
||||
|
||||
//// [destructuringTuple.js]
|
||||
"use strict";
|
||||
var a = tuple[0], b = tuple[1], c = tuple[2], rest = tuple.slice(3);
|
||||
receiver = tuple.slice(0);
|
||||
|
||||
@ -9,3 +9,11 @@ const [a, b, c, ...rest] = tuple;
|
||||
>rest : Symbol(rest, Decl(destructuringTuple.ts, 2, 15))
|
||||
>tuple : Symbol(tuple, Decl(destructuringTuple.ts, 0, 11))
|
||||
|
||||
declare var receiver: typeof tuple;
|
||||
>receiver : Symbol(receiver, Decl(destructuringTuple.ts, 4, 11))
|
||||
>tuple : Symbol(tuple, Decl(destructuringTuple.ts, 0, 11))
|
||||
|
||||
[...receiver] = tuple;
|
||||
>receiver : Symbol(receiver, Decl(destructuringTuple.ts, 4, 11))
|
||||
>tuple : Symbol(tuple, Decl(destructuringTuple.ts, 0, 11))
|
||||
|
||||
|
||||
@ -9,3 +9,14 @@ const [a, b, c, ...rest] = tuple;
|
||||
>rest : string[]
|
||||
>tuple : [boolean, number, ...string[]]
|
||||
|
||||
declare var receiver: typeof tuple;
|
||||
>receiver : [boolean, number, ...string[]]
|
||||
>tuple : [boolean, number, ...string[]]
|
||||
|
||||
[...receiver] = tuple;
|
||||
>[...receiver] = tuple : [boolean, number, ...string[]]
|
||||
>[...receiver] : (string | number | boolean)[]
|
||||
>...receiver : string | number | boolean
|
||||
>receiver : [boolean, number, ...string[]]
|
||||
>tuple : [boolean, number, ...string[]]
|
||||
|
||||
|
||||
@ -1,16 +0,0 @@
|
||||
tests/cases/conformance/es6/destructuring/restElementWithAssignmentPattern3.ts(3,6): error TS2322: Type 'string | number' is not assignable to type 'string'.
|
||||
Type 'number' is not assignable to type 'string'.
|
||||
tests/cases/conformance/es6/destructuring/restElementWithAssignmentPattern3.ts(3,9): error TS2322: Type 'string | number' is not assignable to type 'number'.
|
||||
Type 'string' is not assignable to type 'number'.
|
||||
|
||||
|
||||
==== tests/cases/conformance/es6/destructuring/restElementWithAssignmentPattern3.ts (2 errors) ====
|
||||
var a: string, b: number;
|
||||
var tuple: [string, number] = ["", 1];
|
||||
[...[a, b = 0]] = tuple;
|
||||
~
|
||||
!!! error TS2322: Type 'string | number' is not assignable to type 'string'.
|
||||
!!! error TS2322: Type 'number' is not assignable to type 'string'.
|
||||
~
|
||||
!!! error TS2322: Type 'string | number' is not assignable to type 'number'.
|
||||
!!! error TS2322: Type 'string' is not assignable to type 'number'.
|
||||
@ -1,14 +1,9 @@
|
||||
tests/cases/conformance/es6/destructuring/restElementWithAssignmentPattern4.ts(3,10): error TS2322: Type 'string | number' is not assignable to type 'string'.
|
||||
Type 'number' is not assignable to type 'string'.
|
||||
tests/cases/conformance/es6/destructuring/restElementWithAssignmentPattern4.ts(3,18): error TS2459: Type '(string | number)[]' has no property 'b' and no string index signature.
|
||||
tests/cases/conformance/es6/destructuring/restElementWithAssignmentPattern4.ts(3,18): error TS2459: Type '[string, number]' has no property 'b' and no string index signature.
|
||||
|
||||
|
||||
==== tests/cases/conformance/es6/destructuring/restElementWithAssignmentPattern4.ts (2 errors) ====
|
||||
==== tests/cases/conformance/es6/destructuring/restElementWithAssignmentPattern4.ts (1 errors) ====
|
||||
var a: string, b: number;
|
||||
var tuple: [string, number] = ["", 1];
|
||||
[...{ 0: a = "", b }] = tuple;
|
||||
~
|
||||
!!! error TS2322: Type 'string | number' is not assignable to type 'string'.
|
||||
!!! error TS2322: Type 'number' is not assignable to type 'string'.
|
||||
~
|
||||
!!! error TS2459: Type '(string | number)[]' has no property 'b' and no string index signature.
|
||||
!!! error TS2459: Type '[string, number]' has no property 'b' and no string index signature.
|
||||
@ -3,3 +3,7 @@
|
||||
declare var tuple: [boolean, number, ...string[]];
|
||||
|
||||
const [a, b, c, ...rest] = tuple;
|
||||
|
||||
declare var receiver: typeof tuple;
|
||||
|
||||
[...receiver] = tuple;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user