You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
lang:typescriptIssues affecting TypeScript-specific constructs (not general JS issues)locked-due-to-inactivityPlease open a new issue and fill out the template instead of commenting.status:has prIssues with an accompanying pull request. These issues will probably be fixed soon!
Expected behavior: Trailing comma shouldn't be added after rest parameters. This problem only happens for Typescript files (parser typescript), which breaks builds if someone for example is using Typescript together with Babel 7
@ikatyang No, I let prettier decide which parser to use but parsing .ts files with prettier results in trailing comma (as described above) which in turn when used with webpack -> ts-loader -> babel-loader (a pretty standard approach imo) results in errors thrown when using Babel 7 as its prohibits trailing commas after rest parameters. The only way around it is to either go with --trailingComma none (which breaks our linting) or pollute code with // prettier-ignore comments everywhere we use rest parameters.
I think that prettier should remove / add those trailing commas consistently no matter which parser is used (the trailing comma is for example properly removed / not added when using --parser babylon in js files).
This looks like a bug to me because it's inconsistent with arrays and function arguments (see playground).
Nonetheless, I'm confused (I have never used TypeScript). Shouldn't ts-loader compile your .ts files and output JS to babel-loader? I don't understand why it would break since the syntax is valid TypeScript.
Shouldn't ts-loader compile your .ts files and output JS to babel-loader
But it does just that, exactly. So trailing commas are added by prettier which ts-loader ignores because it's valid typescript but then the output from ts-loader is passed to babel-loader which throws error because it's invalid syntax (Babel 7 only)
@duailibe This still in my opinion doesn't justify inconsistent behavior of prettier because code formatting happens before transpilation and i don't think those trailing commas should be removed when using one parser and left using another.
@tmaciej I wasn't arguing that, I was just trying to figure out if this should be high priority or not (it should be if prettier was printing invalid syntax).
lang:typescriptIssues affecting TypeScript-specific constructs (not general JS issues)locked-due-to-inactivityPlease open a new issue and fill out the template instead of commenting.status:has prIssues with an accompanying pull request. These issues will probably be fixed soon!
Activity
ikatyang commentedon Nov 23, 2017
TypeScript allowed trailing comma being there, so it shouldn't be a problem.
What did you mean
breaks builds? Are you using--parser typescriptfor js files?tmaciej commentedon Nov 23, 2017
@ikatyang No, I let
prettierdecide which parser to use but parsing.tsfiles withprettierresults in trailing comma (as described above) which in turn when used withwebpack -> ts-loader -> babel-loader(a pretty standard approach imo) results in errors thrown when using Babel 7 as its prohibits trailing commas after rest parameters. The only way around it is to either go with--trailingComma none(which breaks our linting) or pollute code with// prettier-ignorecomments everywhere we use rest parameters.I think that
prettiershould remove / add those trailing commas consistently no matter which parser is used (the trailing comma is for example properly removed / not added when using--parser babylonin js files).duailibe commentedon Nov 23, 2017
This looks like a bug to me because it's inconsistent with arrays and function arguments (see playground).
Nonetheless, I'm confused (I have never used TypeScript). Shouldn't ts-loader compile your .ts files and output JS to babel-loader? I don't understand why it would break since the syntax is valid TypeScript.
tmaciej commentedon Nov 23, 2017
@duailibe
But it does just that, exactly. So trailing commas are added by
prettierwhichts-loaderignores because it's valid typescript but then the output fromts-loaderis passed tobabel-loaderwhich throws error because it's invalid syntax (Babel 7 only)ikatyang commentedon Nov 23, 2017
The
breaks buildspart looks like a TS emitter bug:(example.ts)
(example.js)
since the current stage 3 proposal does not allow trailing comma being there, TS emitter should not emit the trailing comma.
duailibe commentedon Nov 23, 2017
@tmaciej Yeah I meant exactly what @ikatyang said, ts-loader should output valid JS, meaning it should remove the comma, not ignore it.
tmaciej commentedon Nov 23, 2017
@duailibe This still in my opinion doesn't justify inconsistent behavior of
prettierbecause code formatting happens before transpilation and i don't think those trailing commas should be removed when using one parser and left using another.duailibe commentedon Nov 23, 2017
@tmaciej I wasn't arguing that, I was just trying to figure out if this should be high priority or not (it should be if prettier was printing invalid syntax).
tmaciej commentedon Nov 23, 2017
@duailibe
Sorry, i misunderstood then.
Anyways, thanks for lighting fast response and PR @duailibe @ikatyang 👍
duailibe commentedon Nov 23, 2017
@tmaciej Thanks for the report!