diff --git a/src/printer.js b/src/printer.js index 344fd354..8408f434 100644 --- a/src/printer.js +++ b/src/printer.js @@ -1741,7 +1741,7 @@ function printFunctionParams(path, print, options) { } const lastParam = util.getLast(path.getValue().params); - const canHaveTrailingComma = lastParam.type !== "RestElement" && !fun.rest; + const canHaveTrailingComma = !(lastParam && lastParam.type === "RestElement") && !fun.rest; return concat([ "(", diff --git a/tests/rest/__snapshots__/jsfmt.spec.js.snap b/tests/rest/__snapshots__/jsfmt.spec.js.snap index 70b59847..79cff5aa 100644 --- a/tests/rest/__snapshots__/jsfmt.spec.js.snap +++ b/tests/rest/__snapshots__/jsfmt.spec.js.snap @@ -10,6 +10,8 @@ function f( superSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperLong, ...args ) {} + +declare class C { f(...superSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperLong): void; } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ declare class C { f( @@ -23,5 +25,11 @@ function f( ...args ) { } + +declare class C { + f( + ...superSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperLong + ): void, +} " `; diff --git a/tests/rest/trailing-commas.js b/tests/rest/trailing-commas.js index 39ebdccd..65a05498 100644 --- a/tests/rest/trailing-commas.js +++ b/tests/rest/trailing-commas.js @@ -9,3 +9,5 @@ function f( superSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperLong, ...args ) {} + +declare class C { f(...superSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperLong): void; }