Move tests with errors to separate file

This commit is contained in:
Yui T 2015-04-16 14:32:23 -07:00
parent 614469462a
commit 55f9aba855
7 changed files with 187 additions and 124 deletions

View file

@ -10,9 +10,6 @@ function a4({x, a}: { x: number, a: number }) { }
a1([1, 2, [["world"]]]);
a1([1, 2, [["world"]], 3]);
a1([1, "string", [["world"]]); // Error
a1([1, 2, [["world"]], "string"]); // Error
// If the declaration includes an initializer expression (which is permitted only
// when the parameter list occurs in conjunction with a function body),
@ -23,7 +20,6 @@ function b2(z = null, o = { x: 0, y: undefined }) { }
function b3({z: {x, y: {j}}} = { z: { x: "hi", y: { j: 1 } } }) { }
interface F1 {
b4(z = 10, [[a, b], d, {u}] = [[1, 2], "string", { u: false }]); // Error, no function body
b5(z, y, [, a, b], {p, m: { q, r}});
}
@ -33,7 +29,6 @@ function b7([[a], b, [[c, d]]] = [[undefined], undefined, [[undefined, undefined
b1([1, 2, 3]); // z is widen to the type any[]
b2("string", { x: 200, y: "string" });
b2("string", { x: 200, y: true });
b2("string", { x: "string", y: true }); // Error
b6(["string", 1, 2]); // Shouldn't be an error
b7([["string"], 1, [[true, false]]]); // Shouldn't be an error
@ -44,39 +39,28 @@ function c0({z: {x, y: {j}}}) { }
function c1({z} = { z: 10 }) { }
function c2({z = 10}) { }
function c3({b}: { b: number|string} = { b: "hello" }) { }
function c4([z], z: number) { } // Duplicate identifier
function c5([a, b, [[c]]]) { }
function c6([a, b, [[c=1]]]) { }
c0({z : { x: 1, y: { j: "world" } }}); // Implied type is { z: {x: any, y: {j: any}} }
c0({z : { x: "string", y: { j: true } }}); // Implied type is { z: {x: any, y: {j: any}} }
c0({z : 1}); // Error, implied type is { z: {x: any, y: {j: any}} }
c1({}); // Error, implied type is {z:number}?
c1({ z: true }); // Error, implied type is {z:number}?
c1(); // Implied type is {z:number}?
c1({ z: 1 }) // Implied type is {z:number}?
c2({}); // Implied type is {z?: number}
c2({z:1}); // Implied type is {z?: number}
c2({z:false}); // Error, implied type is {z?: number}
c3({ b: 1 }); // Implied type is { b: number|string }.
c3({ b: true }); // Error, implied type is { b: number|string }.
c5([1, 2, [["string"]]]); // Implied type is is [any, any, [[any]]]
c5([1, 2, [["string"]], false, true]); // Implied type is is [any, any, [[any]]]
c5([1, 2, false, true]); // Error, implied type is [any, any, [[any]]]
c6([1, 2, [["string"]]]); // Error, implied type is [any, any, [[number]]] // Use initializer
// A parameter can be marked optional by following its name or binding pattern with a question mark (?)
// or by including an initializer.
function d0(x?) { }
function d0(x = 10) { }
function d1([a, b, c]?) { } // Error, binding pattern can't be optional in implementation signature
function d2({x, y, z}?) { } // Error, binding pattern can't be optional in implementation signature
interface F2 {
d3([a, b, c]?);
@ -97,11 +81,6 @@ class C3 implements F2 {
e0([a, b, c]) { }
}
class C4 implements F2 {
d3([a, b, c]?) { }
d4({x, y, c}) { }
e0([a, b, q]) { }
}
function d5({x, y} = { x: 1, y: 2 }) { }
d5(); // Parameter is optional as its declaration included an initializer
@ -115,7 +94,3 @@ function e2({x}: { x: number }) { } // x is type number
function e3({x}: { x?: number }) { } // x is an optional with type number
function e4({x: [number,string,any] }) { } // x has type [any, any, any]
function e5({x: [a, b, c]}: { x: [number, number, number] }) { } // x has type [any, any, any]
function e6({x: [number, number, number]}) { } // should be an error, duplicate identifier;

View file

@ -1,61 +1,67 @@
// If the parameter is a rest parameter, the parameter type is any[]
// A type annotation for a rest parameter must denote an array type.
// A parameter declaration may specify either an identifier or a binding pattern.
// The identifiers specified in parameter declarations and binding patterns
// in a parameter list must be unique within that parameter list.
// RestParameter:
// ... Identifier TypeAnnotation(opt)
type arrayString = Array<String>
type someArray = Array<String> | number[];
type stringOrNumArray = Array<String|Number>;
function a0(...x: [number, number, string]) { } // Error, rest parameter must be array type
function a1(...x: (number|string)[]) { }
function a2(...a) { }
function a3(...a: Array<String>) { }
function a4(...a: arrayString) { }
function a5(...a: stringOrNumArray) { }
function a6(...a: someArray) { } // Error, rest parameter must be array type
function a7(...b?) { } // Error, can't be optional
function a8(...b = [1,2,3]) { } // Error, can't have initializer
function a9([a, b, [[c]]]) { }
function a10([a, b, [[c]], ...x]) { }
function a11([a, b, c, ...x]: number[]) { }
// If the declaration includes a type annotation, the parameter is of that type
function a0([a, b, [[c]]]: [number, number, string[][]]) { }
a0([1, "string", [["world"]]); // Error
a0([1, 2, [["world"]], "string"]); // Error
a1(1, 2, "hello", true); // Error, parameter type is (number|string)[]
var array = [1, 2, 3];
var array2 = [true, false, "hello"];
a2([...array]);
a1(...array);
a1(...array2); // Error parameter type is (number|string)[]
// If the declaration includes an initializer expression (which is permitted only
// when the parameter list occurs in conjunction with a function body),
// the parameter type is the widened form (section 3.11) of the type of the initializer expression.
a9([1, 2, [["string"]], false, true]); // Parameter type is [any, any, [[any]]]
a9([1, 2, "string", false, true]); // Error, parameter type is [any, any, [[any]]]
a9([1, 2]); // Error, parameter type is [any, any, [[any]]]
a10([1, 2, [["string"]], false, true]); // Parameter type is any[]
a10([1, 2, 3, false, true]); // Parameter type is any[]
a10([1, 2]); // Parameter type is any[]
a11([1, 2]); // Parameter type is number[]
a11([1, 2, "string"]); // Error, parameter type is number[]
class C {
constructor(public ...a) { } // Error, rest parameter can't have accessibilityModifier
interface F1 {
b0(z = 10, [[a, b], d, {u}] = [[1, 2], "string", { u: false }]); // Error, no function body
}
// Rest parameter with generic
function foo<T>(...a: T[]) { }
foo("hello", 1, 2); // Error
foo<number|string>("hello", 1, 2);
foo("hello", "world");
function b1(z = null, o = { x: 0, y: undefined }) { }
function b2([a, z, y] = [undefined, null, undefined]) { }
function b3([[a], b, [[c, d]]] = [[undefined], undefined, [[undefined, undefined]]]) { }
enum E { a, b }
const enum E1 { a, b }
function foo1<T extends Number>(...a: T[]) { }
foo1(1, 2, 3, E.a);
foo1(1, 2, 3, E1.a, E.b);
foo1(1, 2, "string", E1.a, E.b); // Error
b1("string", { x: "string", y: true }); // Error
// If the declaration specifies a binding pattern, the parameter type is the implied type of that binding pattern (section 5.1.3)
function c0({z: {x, y: {j}}}) { }
function c1({z} = { z: 10 }) { }
function c2({z = 10}) { }
function c3({b}: { b: number|string } = { b: "hello" }) { }
function c4([z], z: number) { } // Error Duplicate identifier
function c5([a, b, [[c]]]) { }
function c6([a, b, [[c = 1]]]) { }
c0({ z: 1 }); // Error, implied type is { z: {x: any, y: {j: any}} }
c1({}); // Error, implied type is {z:number}?
c1({ z: true }); // Error, implied type is {z:number}?
c2({ z: false }); // Error, implied type is {z?: number}
c3({ b: true }); // Error, implied type is { b: number|string }.
c5([1, 2, false, true]); // Error, implied type is [any, any, [[any]]]
c6([1, 2, [["string"]]]); // Error, implied type is [any, any, [[number]]] // Use initializer
// A parameter can be marked optional by following its name or binding pattern with a question mark (?)
// or by including an initializer. Initializers (including binding property or element initializers) are
// permitted only when the parameter list occurs in conjunction with a function body
function d1([a, b, c]?) { } // Error, binding pattern can't be optional in implementation signature
function d2({x, y, z}?) { } // Error, binding pattern can't be optional in implementation signature
interface F2 {
d3([a, b, c]?);
d4({x, y, z}?);
e0([a, b, c]);
}
class C4 implements F2 {
d3([a, b, c]?) { } // Error, binding pattern can't be optional in implementation signature
d4({x, y, c}) { }
e0([a, b, q]) { }
}
// Destructuring parameter declarations do not permit type annotations on the individual binding patterns,
// as such annotations would conflict with the already established meaning of colons in object literals.
// Type annotations must instead be written on the top- level parameter declaration
function e0({x: [number, number, number]}) { } // should be an error, duplicate identifier;

View file

@ -30,8 +30,7 @@ a9([1, 2, [["string"]], false, true]); // Parameter type is [any, any, [[any]]
a10([1, 2, [["string"]], false, true]); // Parameter type is any[]
a10([1, 2, 3, false, true]); // Parameter type is any[]
a10([1, 2]); // Parameter type is any[]
a11([1, 2]); // Parameter type is number[]
a11([1, 2]); // Parameter type is number[]
// Rest parameter with generic
function foo<T>(...a: T[]) { }

View file

@ -0,0 +1,46 @@
// @target: es6
// If the parameter is a rest parameter, the parameter type is any[]
// A type annotation for a rest parameter must denote an array type.
// RestParameter:
// ... Identifier TypeAnnotation(opt)
type arrayString = Array<String>
type someArray = Array<String> | number[];
type stringOrNumArray = Array<String|Number>;
function a1(...x: (number|string)[]) { }
function a2(...a) { }
function a3(...a: Array<String>) { }
function a4(...a: arrayString) { }
function a5(...a: stringOrNumArray) { }
function a9([a, b, [[c]]]) { }
function a10([a, b, [[c]], ...x]) { }
function a11([a, b, c, ...x]: number[]) { }
var array = [1, 2, 3];
var array2 = [true, false, "hello"];
a2([...array]);
a1(...array);
a9([1, 2, [["string"]], false, true]); // Parameter type is [any, any, [[any]]]
a10([1, 2, [["string"]], false, true]); // Parameter type is any[]
a10([1, 2, 3, false, true]); // Parameter type is any[]
a10([1, 2]); // Parameter type is any[]
a11([1, 2]); // Parameter type is number[]
// Rest parameter with generic
function foo<T>(...a: T[]) { }
foo<number|string>("hello", 1, 2);
foo("hello", "world");
enum E { a, b }
const enum E1 { a, b }
function foo1<T extends Number>(...a: T[]) { }
foo1(1, 2, 3, E.a);
foo1(1, 2, 3, E1.a, E.b);

View file

@ -1,49 +1,36 @@
// Parameter with generic
interface F { }
class Class implements F {
constructor() { }
// If the parameter is a rest parameter, the parameter type is any[]
// A type annotation for a rest parameter must denote an array type.
// RestParameter:
// ... Identifier TypeAnnotation(opt)
type arrayString = Array<String>
type someArray = Array<String> | number[];
type stringOrNumArray = Array<String|Number>;
function a0(...x: [number, number, string]) { } // Error, rest parameter must be array type
function a1(...x: (number|string)[]) { }
function a2(...a: someArray) { } // Error, rest parameter must be array type
function a3(...b?) { } // Error, can't be optional
function a4(...b = [1,2,3]) { } // Error, can't have initializer
function a5([a, b, [[c]]]) { }
function a6([a, b, c, ...x]: number[]) { }
a1(1, 2, "hello", true); // Error, parameter type is (number|string)[]
a1(...array2); // Error parameter type is (number|string)[]
a5([1, 2, "string", false, true]); // Error, parameter type is [any, any, [[any]]]
a5([1, 2]); // Error, parameter type is [any, any, [[any]]]
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
}
class SubClass extends Class {
foo: boolean;
constructor() { super(); }
}
class D implements F {
foo: boolean
constructor() { }
}
class SubD extends D {
bar: number
constructor() {
super();
}
}
// Rest parameter with generic
function foo1<T extends Number>(...a: T[]) { }
foo1(1, 2, "string", E1.a, E.b); // Error
function d0<T extends Class>({x} = { x: new Class() }) { }
function d1<T extends F>({x}: { x: F }) { }
function d2<T extends Class>({x}: { x: Class }) { }
function d3<T extends D>({y}: { y: D }) { }
function d4<T extends D>({y} = { y: new D() }) { }
var obj = new Class();
d0({ x: 1 });
d0({ x: {} });
d0({ x: "string" });
d1({ x: new Class() });
d1({ x: {} });
d1({ x: "string" });
d2({ x: new SubClass() });
d2({ x: {} });
d3({ y: new SubD() });
d3({ y: new SubClass() });
// Error
d3({ y: new Class() });
d3({});
d3({ y: 1 });
d3({ y: "world" });

View file

@ -0,0 +1,50 @@
// Parameter Declaration with generic
interface F { }
class Class implements F {
constructor() { }
}
class SubClass extends Class {
foo: boolean;
constructor() { super(); }
}
class D implements F {
foo: boolean
constructor() { }
}
class SubD extends D {
bar: number
constructor() {
super();
}
}
function d0<T extends Class>({x} = { x: new Class() }) { }
function d1<T extends F>({x}: { x: F }) { }
function d2<T extends Class>({x}: { x: Class }) { }
function d3<T extends D>({y}: { y: D }) { }
function d4<T extends D>({y} = { y: new D() }) { }
var obj = new Class();
d0({ x: 1 });
d0({ x: {} });
d0({ x: "string" });
d1({ x: new Class() });
d1({ x: {} });
d1({ x: "string" });
d2({ x: new SubClass() });
d2({ x: {} });
d3({ y: new SubD() });
d3({ y: new SubClass() });
// Error
d3({ y: new Class() });
d3({});
d3({ y: 1 });
d3({ y: "world" });