Skip to content

Commit f3c327a

Browse files
committed
Add test case for call. Improve other cases.
1 parent 6d7fa63 commit f3c327a

File tree

3 files changed

+73
-7
lines changed

3 files changed

+73
-7
lines changed

tests/baselines/reference/tupleKinds.errors.txt

+23-4
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,45 @@
1-
tests/cases/compiler/tupleKinds.ts(15,5): error TS2322: Type '{}' is not assignable to type '[number, string, boolean, C]'.
1+
tests/cases/compiler/tupleKinds.ts(27,5): error TS2322: Type '{}' is not assignable to type '[number, string, boolean, C]'.
22
Property '0' is missing in type '{}'.
3+
tests/cases/compiler/tupleKinds.ts(31,5): error TS2322: Type '{}' is not assignable to type '[number, string, boolean, C]'.
34

45

5-
==== tests/cases/compiler/tupleKinds.ts (1 errors) ====
6+
==== tests/cases/compiler/tupleKinds.ts (2 errors) ====
67
function tupleId<...V>(y:...V): ...V {
8+
// binds, infers and returns a tuple kind
79
return y;
810
}
11+
function call<...T,U>(f: (ts:...T) => U, ts:...T): U {
12+
// binds, infers a tuple kind, then goes back to fill it in for a function argument
13+
return f(ts);
14+
}
915
function tuple<...T>(...args:...T): ...T {
16+
// uses rest args
1017
return args;
1118
}
1219

13-
let inferredTupleId: [number, string, boolean] = tupleId([1, "foo", false]);
20+
let inferredTupleId: [number, string] = tupleId([1, "foo"]);
21+
let acceptTupleId = tupleId([2, "bar"]);
22+
let compareTupleId: [number, string] = acceptTupleId;
23+
24+
function f(t: [number, string]): number {
25+
return t[0];
26+
}
27+
let inferredCall: number = call(f, [3, "baz"]);
28+
let acceptCall = call(f, [4, "qux"]);
29+
let compareCall: number = acceptCall;
1430

1531
class C { }
1632
let acceptType = tuple(4, "qux", false, new C());
33+
let compareType: [number, string, boolean, C] = acceptType;
34+
~~~~~~~~~~~
35+
!!! error TS2322: Type '{}' is not assignable to type '[number, string, boolean, C]'.
36+
!!! error TS2322: Property '0' is missing in type '{}'.
1737
// TODO: Negative cases don't fail yet when you supply complete type arguments
1838
// TODO: Other negative cases
1939
let typeArguments: [number, string, boolean, C] = tuple<[number, string, boolean, C]>(5, "quack", false, new C());
2040
let inferred: [number, string, boolean, C] = tuple(6, "sequim", false, new C());
2141
~~~~~~~~
2242
!!! error TS2322: Type '{}' is not assignable to type '[number, string, boolean, C]'.
23-
!!! error TS2322: Property '0' is missing in type '{}'.
2443

2544
function spreadIntoUnionNotSupportedYet<...T>(tuple: number | ...T): number {
2645
if(typeof tuple === 'number') {

tests/baselines/reference/tupleKinds.js

+33-2
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,31 @@
11
//// [tupleKinds.ts]
22
function tupleId<...V>(y:...V): ...V {
3+
// binds, infers and returns a tuple kind
34
return y;
45
}
6+
function call<...T,U>(f: (ts:...T) => U, ts:...T): U {
7+
// binds, infers a tuple kind, then goes back to fill it in for a function argument
8+
return f(ts);
9+
}
510
function tuple<...T>(...args:...T): ...T {
11+
// uses rest args
612
return args;
713
}
814

9-
let inferredTupleId: [number, string, boolean] = tupleId([1, "foo", false]);
15+
let inferredTupleId: [number, string] = tupleId([1, "foo"]);
16+
let acceptTupleId = tupleId([2, "bar"]);
17+
let compareTupleId: [number, string] = acceptTupleId;
18+
19+
function f(t: [number, string]): number {
20+
return t[0];
21+
}
22+
let inferredCall: number = call(f, [3, "baz"]);
23+
let acceptCall = call(f, [4, "qux"]);
24+
let compareCall: number = acceptCall;
1025

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

2743
//// [tupleKinds.js]
2844
function tupleId(y) {
45+
// binds, infers and returns a tuple kind
2946
return y;
3047
}
48+
function call(f, ts) {
49+
// binds, infers a tuple kind, then goes back to fill it in for a function argument
50+
return f(ts);
51+
}
3152
function tuple() {
3253
var args = [];
3354
for (var _i = 0; _i < arguments.length; _i++) {
3455
args[_i - 0] = arguments[_i];
3556
}
57+
// uses rest args
3658
return args;
3759
}
38-
var inferredTupleId = tupleId([1, "foo", false]);
60+
var inferredTupleId = tupleId([1, "foo"]);
61+
var acceptTupleId = tupleId([2, "bar"]);
62+
var compareTupleId = acceptTupleId;
63+
function f(t) {
64+
return t[0];
65+
}
66+
var inferredCall = call(f, [3, "baz"]);
67+
var acceptCall = call(f, [4, "qux"]);
68+
var compareCall = acceptCall;
3969
var C = (function () {
4070
function C() {
4171
}
4272
return C;
4373
})();
4474
var acceptType = tuple(4, "qux", false, new C());
75+
var compareType = acceptType;
4576
// TODO: Negative cases don't fail yet when you supply complete type arguments
4677
// TODO: Other negative cases
4778
var typeArguments = tuple(5, "quack", false, new C());

tests/cases/compiler/tupleKinds.ts

+17-1
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,30 @@
11
function tupleId<...V>(y:...V): ...V {
2+
// binds, infers and returns a tuple kind
23
return y;
34
}
5+
function call<...T,U>(f: (ts:...T) => U, ts:...T): U {
6+
// binds, infers a tuple kind, then goes back to fill it in for a function argument
7+
return f(ts);
8+
}
49
function tuple<...T>(...args:...T): ...T {
10+
// uses rest args
511
return args;
612
}
713

8-
let inferredTupleId: [number, string, boolean] = tupleId([1, "foo", false]);
14+
let inferredTupleId: [number, string] = tupleId([1, "foo"]);
15+
let acceptTupleId = tupleId([2, "bar"]);
16+
let compareTupleId: [number, string] = acceptTupleId;
17+
18+
function f(t: [number, string]): number {
19+
return t[0];
20+
}
21+
let inferredCall: number = call(f, [3, "baz"]);
22+
let acceptCall = call(f, [4, "qux"]);
23+
let compareCall: number = acceptCall;
924

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

0 commit comments

Comments
 (0)