question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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 prettier@1.6.1 and typescript@2.2.2.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
JamesHenrycommented, Aug 29, 2017

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

0reactions
azzcommented, Sep 16, 2017

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Executing typescript file gives SyntaxError: Unexpected identifier
So i was able to solve above problem. Actually i was trying to load TypeSciprt file that is .ts file rather than .js...
Read more >
Exception Handling - TypeScript Deep Dive - Gitbook
SyntaxError. Creates an instance representing a syntax error that occurs while parsing code that isn't valid JavaScript. 1***3; // SyntaxError: Unexpected ...
Read more >
Less than (<) - JavaScript - MDN Web Docs
The less than (<) operator returns true if the left operand is less than the right operand, and false otherwise. ... expected output:...
Read more >
Chapter 1. Getting to Know TypeScript
function greet(who: string) { ^ SyntaxError: Unexpected token : The : string is a type ... This program is valid JavaScript (and hence...
Read more >
Troubleshoot 'Uncaught SyntaxError: Unexpected token u in ...
The 'Uncaught SyntaxError: Unexpected token u in JSON at position 0' error is caused when the client has been asked to execute JSON.parse() ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found