1
1
//// [tupleKinds.ts]
2
2
function tupleId < ...V > ( y :...V ) : ...V {
3
+ // binds, infers and returns a tuple kind
3
4
return y ;
4
5
}
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
+ }
5
10
function tuple < ...T > ( ...args :...T ) : ...T {
11
+ // uses rest args
6
12
return args ;
7
13
}
8
14
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 ;
10
25
11
26
class C { }
12
27
let acceptType = tuple ( 4 , "qux" , false , new C ( ) ) ;
28
+ let compareType : [ number , string , boolean , C ] = acceptType ;
13
29
// TODO: Negative cases don't fail yet when you supply complete type arguments
14
30
// TODO: Other negative cases
15
31
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 {
26
42
27
43
//// [tupleKinds.js]
28
44
function tupleId ( y ) {
45
+ // binds, infers and returns a tuple kind
29
46
return y ;
30
47
}
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
+ }
31
52
function tuple ( ) {
32
53
var args = [ ] ;
33
54
for ( var _i = 0 ; _i < arguments . length ; _i ++ ) {
34
55
args [ _i - 0 ] = arguments [ _i ] ;
35
56
}
57
+ // uses rest args
36
58
return args ;
37
59
}
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 ;
39
69
var C = ( function ( ) {
40
70
function C ( ) {
41
71
}
42
72
return C ;
43
73
} ) ( ) ;
44
74
var acceptType = tuple ( 4 , "qux" , false , new C ( ) ) ;
75
+ var compareType = acceptType ;
45
76
// TODO: Negative cases don't fail yet when you supply complete type arguments
46
77
// TODO: Other negative cases
47
78
var typeArguments = tuple ( 5 , "quack" , false , new C ( ) ) ;
0 commit comments