Test assignability checking of object rests

This commit is contained in:
Nathan Shively-Sanders 2016-11-16 13:38:25 -08:00
parent 0e1be3efa1
commit 6b0de7b5ae
7 changed files with 36 additions and 8 deletions

View File

@ -1,14 +1,27 @@
tests/cases/conformance/types/rest/objectRestNegative.ts(2,10): error TS2462: A rest element must be last in a destructuring pattern
tests/cases/conformance/types/rest/objectRestNegative.ts(3,31): error TS2462: A rest element must be last in a destructuring pattern
tests/cases/conformance/types/rest/objectRestNegative.ts(6,17): error TS2700: Rest types may only be created from object types.
tests/cases/conformance/types/rest/objectRestNegative.ts(11,9): error TS2701: The target of an object rest assignment must be a variable or a property access.
tests/cases/conformance/types/rest/objectRestNegative.ts(6,10): error TS2322: Type '{ a: number; }' is not assignable to type '{ a: string; }'.
Types of property 'a' are incompatible.
Type 'number' is not assignable to type 'string'.
tests/cases/conformance/types/rest/objectRestNegative.ts(9,31): error TS2462: A rest element must be last in a destructuring pattern
tests/cases/conformance/types/rest/objectRestNegative.ts(12,17): error TS2700: Rest types may only be created from object types.
tests/cases/conformance/types/rest/objectRestNegative.ts(17,9): error TS2701: The target of an object rest assignment must be a variable or a property access.
==== tests/cases/conformance/types/rest/objectRestNegative.ts (4 errors) ====
==== tests/cases/conformance/types/rest/objectRestNegative.ts (5 errors) ====
let o = { a: 1, b: 'no' };
var { ...mustBeLast, a } = o;
~~~~~~~~~~
!!! error TS2462: A rest element must be last in a destructuring pattern
var b: string;
let notAssignable: { a: string };
({ b, ...notAssignable } = o);
~~~~~~~~~~~~~
!!! error TS2322: Type '{ a: number; }' is not assignable to type '{ a: string; }'.
!!! error TS2322: Types of property 'a' are incompatible.
!!! error TS2322: Type 'number' is not assignable to type 'string'.
function stillMustBeLast({ ...mustBeLast, a }: { a: number, b: string }): void {
~~~~~~~~~~
!!! error TS2462: A rest element must be last in a destructuring pattern

View File

@ -1,6 +1,12 @@
//// [objectRestNegative.ts]
let o = { a: 1, b: 'no' };
var { ...mustBeLast, a } = o;
var b: string;
let notAssignable: { a: string };
({ b, ...notAssignable } = o);
function stillMustBeLast({ ...mustBeLast, a }: { a: number, b: string }): void {
}
function generic<T extends { x, y }>(t: T) {
@ -24,6 +30,9 @@ var __rest = (this && this.__rest) || function (s, e) {
};
var o = { a: 1, b: 'no' };
var a = o.a;
var b;
var notAssignable;
(b = o.b, o, notAssignable = __rest(o, ["b"]));
function stillMustBeLast(_a) {
var a = _a.a;
}

View File

@ -2,7 +2,7 @@
const y = { a: 'yes', b: 'no' };
const o = { x: 1, ...y };
var b;
var rest;
var rest: any;
({ b, ...rest } = o);

View File

@ -12,7 +12,7 @@ const o = { x: 1, ...y };
var b;
>b : Symbol(b, Decl(objectSpreadNoTransform.ts, 2, 3))
var rest;
var rest: any;
>rest : Symbol(rest, Decl(objectSpreadNoTransform.ts, 3, 3))
({ b, ...rest } = o);

View File

@ -17,7 +17,7 @@ const o = { x: 1, ...y };
var b;
>b : any
var rest;
var rest: any;
>rest : any
({ b, ...rest } = o);

View File

@ -1,5 +1,11 @@
let o = { a: 1, b: 'no' };
var { ...mustBeLast, a } = o;
var b: string;
let notAssignable: { a: string };
({ b, ...notAssignable } = o);
function stillMustBeLast({ ...mustBeLast, a }: { a: number, b: string }): void {
}
function generic<T extends { x, y }>(t: T) {

View File

@ -2,5 +2,5 @@
const y = { a: 'yes', b: 'no' };
const o = { x: 1, ...y };
var b;
var rest;
var rest: any;
({ b, ...rest } = o);