Skip to content

Commit 03bca1d

Browse files
authored
Allow trailing commas on lambda type parameter lists (#59612)
1 parent 562b815 commit 03bca1d

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

src/compiler/emitter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4508,7 +4508,7 @@ export function createPrinter(printerOptions: PrinterOptions = {}, handlers: Pri
45084508
if (isFunctionLike(parentNode) && parentNode.typeArguments) { // Quick info uses type arguments in place of type parameters on instantiated signatures
45094509
return emitTypeArguments(parentNode, parentNode.typeArguments);
45104510
}
4511-
emitList(parentNode, typeParameters, ListFormat.TypeParameters);
4511+
emitList(parentNode, typeParameters, ListFormat.TypeParameters | (isArrowFunction(parentNode) ? ListFormat.AllowTrailingComma : ListFormat.None));
45124512
}
45134513

45144514
function emitParameters(parentNode: Node, parameters: NodeArray<ParameterDeclaration>) {

src/testRunner/unittests/printer.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,17 @@ describe("unittests:: PrinterAPI", () => {
100100
ts.ScriptKind.TSX,
101101
));
102102
});
103+
104+
// https://github.com/microsoft/TypeScript/issues/59587
105+
printsCorrectly("lambda type parameter lists in tsx", {}, printer => {
106+
return printer.printFile(ts.createSourceFile(
107+
"source.tsx",
108+
String.raw`export const id = <T,>(id: T): T => id`,
109+
ts.ScriptTarget.ESNext,
110+
/*setParentNodes*/ undefined,
111+
ts.ScriptKind.TSX,
112+
));
113+
});
103114
});
104115

105116
describe("No duplicate ref directives when emiting .d.ts->.d.ts", () => {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const id = <T,>(id: T): T => id;

0 commit comments

Comments
 (0)