-
Notifications
You must be signed in to change notification settings - Fork 143
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Typescript transpile SyntaxError: A trailing comma is not permitted after the rest element #249
Comments
@iki Hmm, I think it's a bug in Prettier if it's inserting a trailing comma. TypeScript 2.9 had a breaking change to disallow trailing commas after rest elements ( https://github.com/Microsoft/TypeScript/wiki/Breaking-Changes#trailing-commas-not-allowed-on-rest-parameters ) and the latest playground shows an error ( https://www.typescriptlang.org/play/#src=const%20%7B%20...rest%2C%20%7D%20%3D%20%7B%7D%3B%0D%0A ). I'd prefer to stick with the latest TypeScript syntax rules unless there's a really compelling reason. There's some more discussion here: prettier/prettier#4624 , although I think that's for a separate TS parsing bug that has since been fixed. |
True, it changes with TS 2.9. However, it's not easy on all projects to switch to 2.9. It needs updating code and some typed dependencies to compile correctly, so we can't use the sucrase powered webpack-serve on most atm. Would you consider making that an option similar to |
I think it should be reasonable to just allow trailing commas here always without need for a new option. Generally Sucrase's philosophy is to skip error validation and leave that to the linter, typechecker, or JS runtime. For example, Babel doesn't let you export the same name twice, but Sucrase does. As you can see from the error message, there's already an explicit check to disallow this case, so the main thing to do is to just remove that check and make sure the comma doesn't cause problems with later parsing. I may want to have a more explicit range of supported TypeScript versions in the future and eventually release a semver-major update that drops support for this case, but for now, TS 2.9 is new enough that it makes sense to support older syntax. |
Fixes #249 Nothing stops us from allowing it at parse time, and it's allowed in TS <2.9, so we support it for now.
Fixes #249 Nothing stops us from allowing it at parse time, and it's allowed in TS <2.9, so we support it for now.
It's forbidden in ES, but allowed in TS, so prettier inserts the comma, see prettier/prettier#3586 and prettier/prettier#3528.
Happens with latest sucrase@3.0.0.
The text was updated successfully, but these errors were encountered: