Skip to content

Commit

Permalink
WIP: allow spreads in type calls
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
KiaraGrouwstra committed Aug 24, 2017
1 parent c274d9b commit bbcd11e
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 2 deletions.
8 changes: 7 additions & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7626,7 +7626,13 @@ namespace ts {

function getTypeFromTypeCallNode(node: TypeCallTypeNode): Type {
const fn = typeNodeToExpression(node.type);
const args = map(node.arguments, typeNodeToExpression);
const args = map(node.arguments, (type: TypeNode) => {
if (type.kind === SyntaxKind.TypeSpread) {
return createSpread(typeNodeToExpression((type as TypeSpreadTypeNode).type));
} else {
return typeNodeToExpression(type);
}
});
const callExpr = createCall(fn, node.typeArguments, args);
return checkExpression(callExpr);
}
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4283,7 +4283,7 @@ namespace ts {

function parseTypeArgumentList() {
parseExpected(SyntaxKind.OpenParenToken);
const result = parseDelimitedList(ParsingContext.TypeArguments, parseType);
const result = parseDelimitedList(ParsingContext.TypeArguments, parseTupleElement);
parseExpected(SyntaxKind.CloseParenToken);
return result;
}
Expand Down
12 changes: 12 additions & 0 deletions tests/baselines/reference/typeCallSpreads.errors.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
tests/cases/compiler/typeCallSpreads.ts(2,13): error TS1005: ')' expected.
tests/cases/compiler/typeCallSpreads.ts(2,19): error TS1005: ';' expected.


==== tests/cases/compiler/typeCallSpreads.ts (2 errors) ====
type Fn = <T>(v: T) => T;
type a = Fn(...[1]);
~~~
!!! error TS1005: ')' expected.
~
!!! error TS1005: ';' expected.

8 changes: 8 additions & 0 deletions tests/baselines/reference/typeCallSpreads.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//// [typeCallSpreads.ts]
type Fn = <T>(v: T) => T;
type a = Fn(...[1]);


//// [typeCallSpreads.js]
[1];
;
2 changes: 2 additions & 0 deletions tests/cases/compiler/typeCallSpreads.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
type Fn = <T>(v: T) => T;
type a = Fn(...[1]);

0 comments on commit bbcd11e

Please sign in to comment.