Skip to content

Commit

Permalink
Add test case for call. Improve other cases.
Browse files Browse the repository at this point in the history
  • Loading branch information
sandersn committed Nov 14, 2015
1 parent 6d7fa63 commit f3c327a
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 7 deletions.
27 changes: 23 additions & 4 deletions tests/baselines/reference/tupleKinds.errors.txt
Original file line number Diff line number Diff line change
@@ -1,26 +1,45 @@
tests/cases/compiler/tupleKinds.ts(15,5): error TS2322: Type '{}' is not assignable to type '[number, string, boolean, C]'.
tests/cases/compiler/tupleKinds.ts(27,5): error TS2322: Type '{}' is not assignable to type '[number, string, boolean, C]'.
Property '0' is missing in type '{}'.
tests/cases/compiler/tupleKinds.ts(31,5): error TS2322: Type '{}' is not assignable to type '[number, string, boolean, C]'.


==== tests/cases/compiler/tupleKinds.ts (1 errors) ====
==== tests/cases/compiler/tupleKinds.ts (2 errors) ====
function tupleId<...V>(y:...V): ...V {
// binds, infers and returns a tuple kind
return y;
}
function call<...T,U>(f: (ts:...T) => U, ts:...T): U {
// binds, infers a tuple kind, then goes back to fill it in for a function argument
return f(ts);
}
function tuple<...T>(...args:...T): ...T {
// uses rest args
return args;
}

let inferredTupleId: [number, string, boolean] = tupleId([1, "foo", false]);
let inferredTupleId: [number, string] = tupleId([1, "foo"]);
let acceptTupleId = tupleId([2, "bar"]);
let compareTupleId: [number, string] = acceptTupleId;

function f(t: [number, string]): number {
return t[0];
}
let inferredCall: number = call(f, [3, "baz"]);
let acceptCall = call(f, [4, "qux"]);
let compareCall: number = acceptCall;

class C { }
let acceptType = tuple(4, "qux", false, new C());
let compareType: [number, string, boolean, C] = acceptType;
~~~~~~~~~~~
!!! error TS2322: Type '{}' is not assignable to type '[number, string, boolean, C]'.
!!! error TS2322: Property '0' is missing in type '{}'.
// TODO: Negative cases don't fail yet when you supply complete type arguments
// TODO: Other negative cases
let typeArguments: [number, string, boolean, C] = tuple<[number, string, boolean, C]>(5, "quack", false, new C());
let inferred: [number, string, boolean, C] = tuple(6, "sequim", false, new C());
~~~~~~~~
!!! error TS2322: Type '{}' is not assignable to type '[number, string, boolean, C]'.
!!! error TS2322: Property '0' is missing in type '{}'.

function spreadIntoUnionNotSupportedYet<...T>(tuple: number | ...T): number {
if(typeof tuple === 'number') {
Expand Down
35 changes: 33 additions & 2 deletions tests/baselines/reference/tupleKinds.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,31 @@
//// [tupleKinds.ts]
function tupleId<...V>(y:...V): ...V {
// binds, infers and returns a tuple kind
return y;
}
function call<...T,U>(f: (ts:...T) => U, ts:...T): U {
// binds, infers a tuple kind, then goes back to fill it in for a function argument
return f(ts);
}
function tuple<...T>(...args:...T): ...T {
// uses rest args
return args;
}

let inferredTupleId: [number, string, boolean] = tupleId([1, "foo", false]);
let inferredTupleId: [number, string] = tupleId([1, "foo"]);
let acceptTupleId = tupleId([2, "bar"]);
let compareTupleId: [number, string] = acceptTupleId;

function f(t: [number, string]): number {
return t[0];
}
let inferredCall: number = call(f, [3, "baz"]);
let acceptCall = call(f, [4, "qux"]);
let compareCall: number = acceptCall;

class C { }
let acceptType = tuple(4, "qux", false, new C());
let compareType: [number, string, boolean, C] = acceptType;
// TODO: Negative cases don't fail yet when you supply complete type arguments
// TODO: Other negative cases
let typeArguments: [number, string, boolean, C] = tuple<[number, string, boolean, C]>(5, "quack", false, new C());
Expand All @@ -26,22 +42,37 @@ function spreadIntoUnionNotSupportedYet<...T>(tuple: number | ...T): number {

//// [tupleKinds.js]
function tupleId(y) {
// binds, infers and returns a tuple kind
return y;
}
function call(f, ts) {
// binds, infers a tuple kind, then goes back to fill it in for a function argument
return f(ts);
}
function tuple() {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i - 0] = arguments[_i];
}
// uses rest args
return args;
}
var inferredTupleId = tupleId([1, "foo", false]);
var inferredTupleId = tupleId([1, "foo"]);
var acceptTupleId = tupleId([2, "bar"]);
var compareTupleId = acceptTupleId;
function f(t) {
return t[0];
}
var inferredCall = call(f, [3, "baz"]);
var acceptCall = call(f, [4, "qux"]);
var compareCall = acceptCall;
var C = (function () {
function C() {
}
return C;
})();
var acceptType = tuple(4, "qux", false, new C());
var compareType = acceptType;
// TODO: Negative cases don't fail yet when you supply complete type arguments
// TODO: Other negative cases
var typeArguments = tuple(5, "quack", false, new C());
Expand Down
18 changes: 17 additions & 1 deletion tests/cases/compiler/tupleKinds.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,30 @@
function tupleId<...V>(y:...V): ...V {
// binds, infers and returns a tuple kind
return y;
}
function call<...T,U>(f: (ts:...T) => U, ts:...T): U {
// binds, infers a tuple kind, then goes back to fill it in for a function argument
return f(ts);
}
function tuple<...T>(...args:...T): ...T {
// uses rest args
return args;
}

let inferredTupleId: [number, string, boolean] = tupleId([1, "foo", false]);
let inferredTupleId: [number, string] = tupleId([1, "foo"]);
let acceptTupleId = tupleId([2, "bar"]);
let compareTupleId: [number, string] = acceptTupleId;

function f(t: [number, string]): number {
return t[0];
}
let inferredCall: number = call(f, [3, "baz"]);
let acceptCall = call(f, [4, "qux"]);
let compareCall: number = acceptCall;

class C { }
let acceptType = tuple(4, "qux", false, new C());
let compareType: [number, string, boolean, C] = acceptType;
// TODO: Negative cases don't fail yet when you supply complete type arguments
// TODO: Other negative cases
let typeArguments: [number, string, boolean, C] = tuple<[number, string, boolean, C]>(5, "quack", false, new C());
Expand Down

0 comments on commit f3c327a

Please sign in to comment.