Skip to content

Commit bbcd11e

Browse files
WIP: allow spreads in type calls
Fixes the third part of microsoft#5453, needed to effectively type `bind` (Function.prototype), `curry` and `compose`. Depends on microsoft#17961 type calls, microsoft#17884 type spread and microsoft#18004 tuple spread. The first 2/3 are included, so changes will look more cluttered here though new changes just span 10 lines over 2 functions. Will properly test this when those are ready -- now still broken.
1 parent c274d9b commit bbcd11e

File tree

5 files changed

+30
-2
lines changed

5 files changed

+30
-2
lines changed

src/compiler/checker.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -7626,7 +7626,13 @@ namespace ts {
76267626

76277627
function getTypeFromTypeCallNode(node: TypeCallTypeNode): Type {
76287628
const fn = typeNodeToExpression(node.type);
7629-
const args = map(node.arguments, typeNodeToExpression);
7629+
const args = map(node.arguments, (type: TypeNode) => {
7630+
if (type.kind === SyntaxKind.TypeSpread) {
7631+
return createSpread(typeNodeToExpression((type as TypeSpreadTypeNode).type));
7632+
} else {
7633+
return typeNodeToExpression(type);
7634+
}
7635+
});
76307636
const callExpr = createCall(fn, node.typeArguments, args);
76317637
return checkExpression(callExpr);
76327638
}

src/compiler/parser.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -4283,7 +4283,7 @@ namespace ts {
42834283

42844284
function parseTypeArgumentList() {
42854285
parseExpected(SyntaxKind.OpenParenToken);
4286-
const result = parseDelimitedList(ParsingContext.TypeArguments, parseType);
4286+
const result = parseDelimitedList(ParsingContext.TypeArguments, parseTupleElement);
42874287
parseExpected(SyntaxKind.CloseParenToken);
42884288
return result;
42894289
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
tests/cases/compiler/typeCallSpreads.ts(2,13): error TS1005: ')' expected.
2+
tests/cases/compiler/typeCallSpreads.ts(2,19): error TS1005: ';' expected.
3+
4+
5+
==== tests/cases/compiler/typeCallSpreads.ts (2 errors) ====
6+
type Fn = <T>(v: T) => T;
7+
type a = Fn(...[1]);
8+
~~~
9+
!!! error TS1005: ')' expected.
10+
~
11+
!!! error TS1005: ';' expected.
12+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//// [typeCallSpreads.ts]
2+
type Fn = <T>(v: T) => T;
3+
type a = Fn(...[1]);
4+
5+
6+
//// [typeCallSpreads.js]
7+
[1];
8+
;
+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
type Fn = <T>(v: T) => T;
2+
type a = Fn(...[1]);

0 commit comments

Comments
 (0)