babel: @babel/preset-typescript doesn't appear to support generic functions

Bug Report

Current Behavior Even the simplest example of a generic function, taken straight from the TypeScript docs, fails to parse.

Input Code https://babeljs.io/en/repl#?babili=false&browsers=&build=&builtIns=false&spec=false&loose=false&code_lz=GYVwdgxgLglg9mABDAJgUzLKBPAPAFQD4AKAQwCcBzALkXwEpb9EBvAKEU8XLShHKQVKAbjYBfIA&debug=false&forceAllTransforms=false&shippedProposals=false&circleciRepo=&evaluate=true&fileSize=false&timeTravel=false&sourceType=module&lineWrap=false&presets=typescript&prettier=false&targets=&version=7.6.4&externalPlugins=

function identity<T>(arg: T): T {
    return arg;
}
/repl: Unexpected token, expected "(" (1:17)

> 1 | function identity<T>(arg: T): T {
    |                  ^
  2 |     return arg;
  3 | }

Expected behavior/code This was taken from the TypeScript docs here: https://www.typescriptlang.org/docs/handbook/generics.html

Babel Configuration (.babelrc, package.json, cli command) (included in Babel REPL link)

Environment (included in Babel REPL link)

Additional context/Screenshots Unsurprisingly, the same problem seemed to happen with generic arrow functions.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 1
  • Comments: 18 (5 by maintainers)

Most upvoted comments

Ignore what I’ve said here : https://github.com/babel/babel/issues/10605#issuecomment-546104677 My issue root case was not babel ❤️ Bad conincidence that it happened to stumble on this issue right now. My issue was that next doesn’t transpile ts files imported outside of its root directory (e.g. a root shared folder above the folder containing next src), aka something I can fix in my code 🌹