Added tests.

This commit is contained in:
Daniel Rosenwasser 2015-01-14 17:02:31 -08:00
parent bfe63cc4cb
commit dafe7c8958
12 changed files with 172 additions and 0 deletions

View file

@ -0,0 +1,14 @@
tests/cases/conformance/es6/destructuring/optionalBindingParameters1.ts(8,5): error TS2345: Argument of type '[boolean, number, string]' is not assignable to parameter of type '[string, number, boolean]'.
==== tests/cases/conformance/es6/destructuring/optionalBindingParameters1.ts (1 errors) ====
function foo([x,y,z]?: [string, number, boolean]) {
}
foo(["", 0, false]);
foo([false, 0, ""]);
~~~~~~~~~~~~~~
!!! error TS2345: Argument of type '[boolean, number, string]' is not assignable to parameter of type '[string, number, boolean]'.

View file

@ -0,0 +1,16 @@
//// [optionalBindingParameters1.ts]
function foo([x,y,z]?: [string, number, boolean]) {
}
foo(["", 0, false]);
foo([false, 0, ""]);
//// [optionalBindingParameters1.js]
function foo(_a) {
var x = _a[0], y = _a[1], z = _a[2];
}
foo(["", 0, false]);
foo([false, 0, ""]);

View file

@ -0,0 +1,18 @@
tests/cases/conformance/es6/destructuring/optionalBindingParameters2.ts(8,5): error TS2345: Argument of type '{ x: boolean; y: number; z: string; }' is not assignable to parameter of type '{ x: string; y: number; z: boolean; }'.
Types of property 'x' are incompatible.
Type 'boolean' is not assignable to type 'string'.
==== tests/cases/conformance/es6/destructuring/optionalBindingParameters2.ts (1 errors) ====
function foo({ x, y, z }?: { x: string; y: number; z: boolean }) {
}
foo({ x: "", y: 0, z: false });
foo({ x: false, y: 0, z: "" });
~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2345: Argument of type '{ x: boolean; y: number; z: string; }' is not assignable to parameter of type '{ x: string; y: number; z: boolean; }'.
!!! error TS2345: Types of property 'x' are incompatible.
!!! error TS2345: Type 'boolean' is not assignable to type 'string'.

View file

@ -0,0 +1,16 @@
//// [optionalBindingParameters2.ts]
function foo({ x, y, z }?: { x: string; y: number; z: boolean }) {
}
foo({ x: "", y: 0, z: false });
foo({ x: false, y: 0, z: "" });
//// [optionalBindingParameters2.js]
function foo(_a) {
var x = _a.x, y = _a.y, z = _a.z;
}
foo({ x: "", y: 0, z: false });
foo({ x: false, y: 0, z: "" });

View file

@ -0,0 +1,15 @@
tests/cases/conformance/es6/destructuring/optionalBindingParametersInOverloads1.ts(9,5): error TS2345: Argument of type '[boolean, number, string]' is not assignable to parameter of type '[string, number, boolean]'.
==== tests/cases/conformance/es6/destructuring/optionalBindingParametersInOverloads1.ts (1 errors) ====
function foo([x, y, z] ?: [string, number, boolean]);
function foo(...rest: any[]) {
}
foo(["", 0, false]);
foo([false, 0, ""]);
~~~~~~~~~~~~~~
!!! error TS2345: Argument of type '[boolean, number, string]' is not assignable to parameter of type '[string, number, boolean]'.

View file

@ -0,0 +1,20 @@
//// [optionalBindingParametersInOverloads1.ts]
function foo([x, y, z] ?: [string, number, boolean]);
function foo(...rest: any[]) {
}
foo(["", 0, false]);
foo([false, 0, ""]);
//// [optionalBindingParametersInOverloads1.js]
function foo() {
var rest = [];
for (var _i = 0; _i < arguments.length; _i++) {
rest[_i - 0] = arguments[_i];
}
}
foo(["", 0, false]);
foo([false, 0, ""]);

View file

@ -0,0 +1,19 @@
tests/cases/conformance/es6/destructuring/optionalBindingParametersInOverloads2.ts(9,5): error TS2345: Argument of type '{ x: boolean; y: number; z: string; }' is not assignable to parameter of type '{ x: string; y: number; z: boolean; }'.
Types of property 'x' are incompatible.
Type 'boolean' is not assignable to type 'string'.
==== tests/cases/conformance/es6/destructuring/optionalBindingParametersInOverloads2.ts (1 errors) ====
function foo({ x, y, z }?: { x: string; y: number; z: boolean });
function foo(...rest: any[]) {
}
foo({ x: "", y: 0, z: false });
foo({ x: false, y: 0, z: "" });
~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2345: Argument of type '{ x: boolean; y: number; z: string; }' is not assignable to parameter of type '{ x: string; y: number; z: boolean; }'.
!!! error TS2345: Types of property 'x' are incompatible.
!!! error TS2345: Type 'boolean' is not assignable to type 'string'.

View file

@ -0,0 +1,20 @@
//// [optionalBindingParametersInOverloads2.ts]
function foo({ x, y, z }?: { x: string; y: number; z: boolean });
function foo(...rest: any[]) {
}
foo({ x: "", y: 0, z: false });
foo({ x: false, y: 0, z: "" });
//// [optionalBindingParametersInOverloads2.js]
function foo() {
var rest = [];
for (var _i = 0; _i < arguments.length; _i++) {
rest[_i - 0] = arguments[_i];
}
}
foo({ x: "", y: 0, z: false });
foo({ x: false, y: 0, z: "" });

View file

@ -0,0 +1,8 @@

function foo([x,y,z]?: [string, number, boolean]) {
}
foo(["", 0, false]);
foo([false, 0, ""]);

View file

@ -0,0 +1,8 @@

function foo({ x, y, z }?: { x: string; y: number; z: boolean }) {
}
foo({ x: "", y: 0, z: false });
foo({ x: false, y: 0, z: "" });

View file

@ -0,0 +1,9 @@

function foo([x, y, z] ?: [string, number, boolean]);
function foo(...rest: any[]) {
}
foo(["", 0, false]);
foo([false, 0, ""]);

View file

@ -0,0 +1,9 @@

function foo({ x, y, z }?: { x: string; y: number; z: boolean });
function foo(...rest: any[]) {
}
foo({ x: "", y: 0, z: false });
foo({ x: false, y: 0, z: "" });