Skip to content

Valid TypeScript has "SyntaxError: '=' expected." #2702

Closed

Description

@abirmingham

The following code causes a SyntaxError, despite being syntactically/stylistically correct:

const bar = (...varargs:any[]) => {
  console.log(varargs);
};

const foo = (x:string):void => (
  bar(
    x,
    () => {},
    () => {}
  )
);

Here is the result:

SyntaxError: '=' expected. (6:6)
  4 | 
  5 | const foo = (x:string):void => (
> 6 |   bar(
    |      ^
  7 |     x,
  8 |     () => {},
  9 |     () => {}

Here is a link to the issue reproduced in the prettier playground. Note that if the parser is changed to babylon then there is no error shown.

Thanks for any assistance!

EDIT: I'm using [email protected] and [email protected].

Activity

  1. vjeux commented on Aug 29, 2017

    @vjeux
    Contributor

    @JamesHenry do you know what's going on here?

  2. JamesHenry commented on Aug 29, 2017

    @JamesHenry
    Collaborator

    Funky, seems to be an issue with the TypeScript 2.5 RC. This parses fine in stable TypeScript 2.4, but not in 2.5.1.

    I'll report it to the TS team

  3. abirmingham commented on Aug 29, 2017

    @abirmingham
    Author

    @JamesHenry many thanks!

    I should have mentioned that I'm using [email protected] and [email protected]. The error does not appear when I run tsc directly (or through webpack's ts-loader).

  4. JamesHenry commented on Aug 29, 2017

    @JamesHenry
    Collaborator

    Prettier bundles its required TypeScript version, so your installed version (of 2.2.2) isn't actually relevant to the issue. Everyone who installs a particular version of prettier gets the same underlying TypeScript parser version.

    Here is the bug report: microsoft/TypeScript#18123

  5. alexburner commented on Aug 29, 2017

    @alexburner

    @JamesHenry it seems strange Prettier includes its own version of TypeScript, instead of using the version provided by the hosting project. What if there's a significant/breaking change between TS versions?

  6. vjeux commented on Aug 29, 2017

    @vjeux
    Contributor

    @alexburner so far all of the parsers we've made didn't introduce breaking changes. It's extremely onerous for them as they break compatibility with all the codebases written in that language, so they usually end up not doing it.

    With prettier we're using versions close to master of the next release, so that when they ship a big new major version, we already have had support for all the new syntax additions for a while.

    For prettier, we are hitting the internals of those parsers and none of the parsers are maintaining backward compatibility of the internals, so it would be a significant effort to try and be compatible with arbitrary versions of the parsers that happen to be in your project. It also would make our life harder with integrations as to how to find the right version.

  7. alexburner commented on Aug 29, 2017

    @alexburner

    Thanks for the quick response!

    For prettier, we are hitting the internals of those parsers and none of the parsers are maintaining backward compatibility of the internals, so it would be a significant effort to try and be compatible with arbitrary versions of the parsers that happen to be in your project.

    That sounds like plenty of reason right there, I hadn't realized your work required customizing the internals of those parsers. That would make full version compatibility much more difficult.

  8. added
    scope:dependencyIssues that cannot be solved inside Prettier itself, and must be fixed in a dependency
    priority:highCode is printed in a way that alters the AST, breaks syntax, or is a significant regression. Urgent!
    lang:typescriptIssues affecting TypeScript-specific constructs (not general JS issues)
    on Aug 29, 2017
  9. JamesHenry commented on Sep 15, 2017

    @JamesHenry
    Collaborator

    @azz I'm on mobile while travelling, so hard to follow up, but the underlying TypeScript issue for this was fixed. Not sure if the TS version was bumped when releasing 1.7.0?

  10. self-assigned this
    on Sep 16, 2017
  11. azz commented on Sep 16, 2017

    @azz
    Member

    This is not fixed in lastest (2.5.2) but is fixed in insiders (2.5.3-insiders.20170909)

  12. added
    locked-due-to-inactivityPlease open a new issue and fill out the template instead of commenting.
    on Jul 6, 2018
  13. locked as resolved and limited conversation to collaborators on Jul 6, 2018
  14. added theissue type on Mar 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

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.priority:highCode is printed in a way that alters the AST, breaks syntax, or is a significant regression. Urgent!scope:dependencyIssues that cannot be solved inside Prettier itself, and must be fixed in a dependency

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions