Assignment rest element pretends to get the contextual element type

This commit is contained in:
Jason Freeman
2015-04-10 16:03:54 -07:00
parent f84ebba852
commit 5bfbcdcd25
11 changed files with 92 additions and 7 deletions

View File

@@ -0,0 +1,8 @@
//// [nonIterableRestElement1.ts]
var c = {};
[...c] = ["", 0];
//// [nonIterableRestElement1.js]
var c = {};
_a = ["", 0], c = _a.slice(0);
var _a;

View File

@@ -0,0 +1,12 @@
=== tests/cases/conformance/es6/destructuring/nonIterableRestElement1.ts ===
var c = {};
>c : {}
>{} : {}
[...c] = ["", 0];
>[...c] = ["", 0] : (string | number)[]
>[...c] : {}[]
>...c : unknown
>c : {}
>["", 0] : (string | number)[]

View File

@@ -0,0 +1,7 @@
//// [nonIterableRestElement2.ts]
var c = {};
[...c] = ["", 0];
//// [nonIterableRestElement2.js]
var c = {};
[...c] = ["", 0];

View File

@@ -0,0 +1,12 @@
=== tests/cases/conformance/es6/destructuring/nonIterableRestElement2.ts ===
var c = {};
>c : {}
>{} : {}
[...c] = ["", 0];
>[...c] = ["", 0] : (string | number)[]
>[...c] : {}[]
>...c : any
>c : {}
>["", 0] : (string | number)[]

View File

@@ -0,0 +1,10 @@
tests/cases/conformance/es6/destructuring/nonIterableRestElement3.ts(2,5): error TS2322: Type '(string | number)[]' is not assignable to type '{ bogus: number; }'.
Property 'bogus' is missing in type '(string | number)[]'.
==== tests/cases/conformance/es6/destructuring/nonIterableRestElement3.ts (1 errors) ====
var c = { bogus: 0 };
[...c] = ["", 0];
~
!!! error TS2322: Type '(string | number)[]' is not assignable to type '{ bogus: number; }'.
!!! error TS2322: Property 'bogus' is missing in type '(string | number)[]'.

View File

@@ -0,0 +1,8 @@
//// [nonIterableRestElement3.ts]
var c = { bogus: 0 };
[...c] = ["", 0];
//// [nonIterableRestElement3.js]
var c = { bogus: 0 };
_a = ["", 0], c = _a.slice(0);
var _a;

View File

@@ -1,14 +1,11 @@
tests/cases/conformance/es6/destructuring/restElementWithAssignmentPattern2.ts(2,5): error TS2461: Type '{ 0: string; b: number; }' is not an array type.
tests/cases/conformance/es6/destructuring/restElementWithAssignmentPattern2.ts(2,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/restElementWithAssignmentPattern2.ts(2,18): error TS2459: Type '(string | number)[]' has no property 'b' and no string index signature.
==== tests/cases/conformance/es6/destructuring/restElementWithAssignmentPattern2.ts (3 errors) ====
==== tests/cases/conformance/es6/destructuring/restElementWithAssignmentPattern2.ts (2 errors) ====
var a: string, b: number;
[...{ 0: a = "", b }] = ["", 1];
~~~~~~~~~~~~~~~~
!!! error TS2461: Type '{ 0: string; b: number; }' is not an array type.
~
!!! error TS2322: Type 'string | number' is not assignable to type 'string'.
!!! error TS2322: Type 'number' is not assignable to type 'string'.

View File

@@ -0,0 +1,2 @@
var c = {};
[...c] = ["", 0];

View File

@@ -0,0 +1,3 @@
//@target: ES6
var c = {};
[...c] = ["", 0];

View File

@@ -0,0 +1,2 @@
var c = { bogus: 0 };
[...c] = ["", 0];