Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeScript syntax error in combination with arrow functions, generics and async/await #6360

Closed
sbusch opened this issue Feb 8, 2019 · 7 comments

Comments

@sbusch
Copy link

sbusch commented Feb 8, 2019

Is this a bug report?

Yes, this is a bug report.

I get a syntax error with the following code, which I reduced as much as possible to just trigger the error:

const first = async <X extends {}>() => {
  await something();
};

const second = async <Y extends {}>() => {};

Did you try recovering your dependencies?

Yes, but recovering didn't help.

Output of yarn --version:

1.13.0

Environment

$ npx create-react-app --info

Environment Info:

  System:
    OS: macOS 10.14.2
    CPU: x64 Intel(R) Core(TM) i5-7360U CPU @ 2.30GHz
  Binaries:
    Node: 11.9.0 - /usr/local/bin/node
    Yarn: 1.13.0 - /usr/local/bin/yarn
    npm: 6.7.0 - /usr/local/bin/npm
  Browsers:
    Chrome: 71.0.3578.98
    Firefox: 64.0.2
    Safari: 12.0.2
  npmPackages:
    react: ^16.8.1 => 16.8.1 
    react-dom: ^16.8.1 => 16.8.1 
    react-scripts: 2.1.3 => 2.1.3 
  npmGlobalPackages:
    create-react-app: Not Found

Steps to Reproduce

See "Reproducible Demo".

Expected Behavior

I wouldn't expect a syntax error (other errors with this code, yes, but no syntax error)

AFAIK the code is valid TypeScript.

Actual Behavior

Syntax error:

Failed to compile.

./src/index.tsx
SyntaxError: /Users/sebu/Desktop/2019-02-08-cra-ts-syntaxerror/src/index.tsx: Unexpected token, expected ";" (5:24)

  3 | };
  4 | 
> 5 | const second = async <Y extends {}>() => {};
    |                         ^
  6 | 

As colorized screenshot:

bildschirmfoto 2019-02-08 um 09 59 07

Reproducible Demo

Reproducible repo at https://github.com/sbusch/2019-02-08-cra-ts-syntaxerror which I stripped down as much as possible.

Problem is in src/index.tsx:

Steps to reproduce:

git clone https://github.com/sbusch/2019-02-08-cra-ts-syntaxerror.git

cd 2019-02-08-cra-ts-syntaxerror

yarn install

BROWSER=none yarn start
@sbusch
Copy link
Author

sbusch commented Feb 22, 2019

The problem still exists with project generated by 2.1.5, see branch react-scripts-2.1.5 at my repro.

I also tested with new project generated by current HEAD 01fbb79 of create-react-app, with the same outcome.

@nsmithdev
Copy link

Add TypeScript linting support
Issue #5641
Pull #6513

@xaviergonz
Copy link

xaviergonz commented Apr 17, 2019

I think this error comes from babel interaction with typescript, since it works OK when using the typescript compiler directly yet it fails when compiling typescript through babel, so I'd also try to post it into the babel repo

@xaviergonz
Copy link

xaviergonz commented Apr 17, 2019

Apparently it got fixed here

babel/babel#9560

so it should be fixed by upgrading babel to the latest version

@ianschmitz
Copy link
Contributor

You can try our latest 3.0 alpha which has updated versions of babel: #6475

@sbusch
Copy link
Author

sbusch commented Jul 10, 2019

I can confirm his is no longer an issue with CRA 3.0 (I'm currently using 3.0.1).

@sbusch sbusch closed this as completed Jul 10, 2019
@lock lock bot locked and limited conversation to collaborators Jul 15, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants
@sbusch @nsmithdev @xaviergonz @ianschmitz and others