Skip to content

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

Closed

Description

@sbusch

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

Activity

  1. sbusch commented on Feb 22, 2019

    @sbusch
    Author

    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.

  2. nsmithdev commented on Mar 11, 2019

    @nsmithdev

    Add TypeScript linting support
    Issue #5641
    Pull #6513

  3. xaviergonz commented on Apr 17, 2019

    @xaviergonz

    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

  4. xaviergonz commented on Apr 17, 2019

    @xaviergonz

    Apparently it got fixed here

    babel/babel#9560

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

  5. ianschmitz commented on Apr 18, 2019

    @ianschmitz
    Contributor

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

  6. sbusch commented on Jul 10, 2019

    @sbusch
    Author

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

  7. locked and limited conversation to collaborators on Jul 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions