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.
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)
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 🌹