Skip to content

[@babel/preset-typescript] Parse error when an explicit type parameter is a generic arrow function #11969

@lazytype

Description

@lazytype

Bug Report

  • [~] I would like to work on a fix!

Current behavior
Parse error when an explicit type parameter is a generic arrow function

Input Code

f<<T>(value: T) => void>(g);

Expected behavior
The type parameter should be stripped from the code:

f(g);

Babel Configuration (babel.config.js, .babelrc, package.json#babel, cli command, .eslintrc)

  • Filename: babel.config.js
{
  "presets": [
    ["@babel/preset-env", { "targets": { "node": "current" } }],
    "@babel/typescript"
  ],
  "plugins": [
    "@babel/plugin-syntax-class-properties"
  ]
}

Environment

  • Babel version(s): v7
  • Node/npm version: Node 13.8.0/npm 6.13.6
  • OS:macOS 10.15.5
  • Monorepo: yes
  • How you are using Babel: cli

Possible Solution
Note that these two examples both parse correctly:

f< <T>(value: T) => void>(g); // Note the space between the two "<"
f<U, <T>(value: T) => void>(g);

My guess is that the parser thinks it's encountered a << operator. I think C++ also used to have this problem in its parser 😅.

Additional context
TypeScript playground

Metadata

Metadata

Assignees

Labels

area: typescriptoutdatedA closed issue/PR that is archived due to age. Recommended to make a new issuepkg: parser

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions