Giter Club home page Giter Club logo

Comments (3)

alangpierce avatar alangpierce commented on May 15, 2024

@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.

from sucrase.

iki avatar iki commented on May 15, 2024

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 enableLegacyTypeScriptModuleInterop?

from sucrase.

alangpierce avatar alangpierce commented on May 15, 2024

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.

from sucrase.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.