Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@babel/preset-typescript and generic arrow function (<T extends {}>) #9086

Closed
Tsury opened this issue Nov 26, 2018 · 8 comments
Closed

@babel/preset-typescript and generic arrow function (<T extends {}>) #9086

Tsury opened this issue Nov 26, 2018 · 8 comments
Labels
area: typescript awaiting reply outdated A closed issue/PR that is archived due to age. Recommended to make a new issue
Milestone

Comments

@Tsury
Copy link

Tsury commented Nov 26, 2018

Bug Report

Current Behavior
I have an anonymous generic arrow function which looks like this:
const myFunc = <T extends {}>(params: any): any => { }

I'm using vscode and everything is fine, but when I try to build, I get this error from babel-loader:
Unexpected token, expected ";"

Input Code

  • REPL or Repo link if applicable:
`const myFunc = <T extends {}>(params: any): any => { }`

Expected behavior/code
Should just build my code

Babel Configuration (.babelrc, package.json, cli command)

My .babelrc has this global preset:

  "presets": [
    "@babel/preset-typescript"
  ],

and this env preset:
["@babel/preset-react", { "development": true }]

These global plugins:

    ["@babel/plugin-proposal-decorators", { "legacy" : true }],
    ["@babel/plugin-proposal-class-properties", { "loose" : true }],
    "@babel/plugin-syntax-dynamic-import",
    ["import", { "libraryName": "antd", "style": true }]

And these env plugins:

        ["@babel/plugin-transform-react-display-name"],
        ["emotion", { "sourceMap": true, "autoLabel": true }]

babel-loader in webpack has no additional settings to the .babelrc file.

Environment

  • Babel version(s): 7.1.6
  • Node/npm version: Node 11.0.0/npm 6.2.0
  • OS: Windows 10
  • How you are using Babel: loader

Possible Solution

Additional context/Screenshots
Add any other context about the problem here. If applicable, add screenshots to help explain.

@babel-bot
Copy link
Collaborator

Hey @Tsury! We really appreciate you taking the time to report an issue. The collaborators
on this project attempt to help as many people as possible, but we're a limited number of volunteers,
so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack
community that typically always has someone willing to help. You can sign-up here
for an invite.

@nicolo-ribaudo
Copy link
Member

This seems to work on master

@lapto
Copy link

lapto commented Nov 27, 2018

Have the same issue, we had to return to react-native-typescript-transformer.

#7504 is probably related.

@danez
Copy link
Member

danez commented Nov 29, 2018

I'm not able to reproduce this with 7.1.6. Would you be able to paste the complete stacktrace?

@lapto
Copy link

lapto commented Nov 30, 2018

@danez Im running it using react-native. Seems like metro is stingy with its stacktrace but here it is:

export const test = async <P extends IP>(body: IE<P>): Promise<void> => {

at _class.raise (*/node_modules/@babel/parser/lib/index.js:4028:15) at _class.unexpected (*/node_modules/@babel/parser/lib/index.js:5343:16) at _class.semicolon (*/node_modules/@babel/parser/lib/index.js:5327:40) at _class.parseVarStatement (*/node_modules/@babel/parser/lib/index.js:7729:10) at _class.parseStatementContent (*/node_modules/@babel/parser/lib/index.js:7327:21) at _class.parseStatementContent (*/node_modules/@babel/parser/lib/index.js:10082:58) at _class.parseStatement (*/node_modules/@babel/parser/lib/index.js:7277:17) at _class.parseExportDeclaration (*/node_modules/@babel/parser/lib/index.js:8365:17) at _class.parseExportDeclaration (*/node_modules/@babel/parser/lib/index.js:10200:68) at _class.parseExport (*/node_modules/@babel/parser/lib/index.js:8312:31)

I checked the version written in package.json of node_mules/@babel and its "version": "7.1.6",

@e-r-w
Copy link

e-r-w commented Dec 3, 2018

If it helps, I've come across this issue too:

const someFunc = () => Promise.resolve(1);

export const worksFine = async <T>(thing: T): Promise<T> => {
  return someFunc().then(() => thing);
};

export const itsBroken = async <T>(thing: T): Promise<T> => {
  return await someFunc().then(() => thing);
};

Seems to break when you have the await keyword mixed in with generic arrow functions. @babel/core 7.1.6.

@danez
Copy link
Member

danez commented Dec 3, 2018

The problem with typescript and async/await has been fixed in #9055 and will be released with 7.2.0.

@danez danez added this to the 7.2.0 milestone Dec 3, 2018
@danez
Copy link
Member

danez commented Dec 3, 2018

Please try again. It should work now with 7.2.0, as we fixed several issues mentioned in this issue.

If there are still problems please open new issues for them. Thank you.

@danez danez closed this as completed Dec 3, 2018
@lock lock bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Mar 4, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Mar 4, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: typescript awaiting reply outdated A closed issue/PR that is archived due to age. Recommended to make a new issue
Projects
None yet
Development

No branches or pull requests

6 participants