Skip to content

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

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:

constfirst=async<Xextends{}>()=>{awaitsomething();};constsecond=async<Yextends{}>()=>{};

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

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