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

[typescript] Generic parameter is not removed when using the optional chaining operator #11813

RafaelSalguero opened this issue Jul 9, 2020 · 3 comments


Copy link

@RafaelSalguero RafaelSalguero commented Jul 9, 2020

Bug Report

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

Current behavior
Generic parameters are not removed from function calls after using the optional chaining operator

let x: number[] = [1,2,3];<boolean>(x => x > 1);

//error (generic parameter not removed):
let y: number[] = [1,2,3];
y?.map<boolean>(x => x > 1);

Expected behavior
Generic parameters should be removed from function calls after the optional chaining operator

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

  • Filename: babel.config.json
  "presets": [
        "isTSX": true,
        "allExtensions": true


    OS: Windows 10 10.0.19041
    Node: 12.18.0 - C:\Program Files\nodejs\node.EXE
    npm: 6.14.4 - C:\Program Files\nodejs\npm.CMD   
    @babel/cli: ^7.10.4 => 7.10.4
    @babel/core: ^7.10.4 => 7.10.4
    @babel/preset-typescript: ^7.10.4 => 7.10.4    
  • Monorepo: no
  • How you are using Babel: cli
Copy link

@babel-bot babel-bot commented Jul 9, 2020

Hey @RafaelSalguero! 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."

Copy link

@JLHwung JLHwung commented Jul 9, 2020

x?.map<boolean>() is an OptionalCallExpression, we shall remove its typeParameters like we did for CallExpression

CallExpression(path) {
path.node.typeParameters = null;

@RafaelSalguero If you are willing to send a PR, please leave a message so I will assign this issue to you, thanks.

If you don't know how to clone Babel, follow these steps: (you need to have make and yarn available on your machine).

  1. Write a comment there to let other possible contributors know that you are working on this bug.
  2. Fork the repo
  3. Run git clone<YOUR_USERNAME>/babel.git && cd babel
  4. Run make bootstrap
  5. Wait
  6. Run make watch (or make build whenever you change a file)
  7. Add a test (only input.js; output.js will be automatically generated) to packages/babel-plugin-transform-typescript/test/fixtures/type-arguments
  8. Update the code!
  9. yarn jest transform-typescript to run the tests
    • If some test outputs don't match but the new results are correct, you can delete the bad output.js files and run the tests again
  10. If it is working, run make test to run all the tests
  11. Run git push and open a PR!
Copy link
Contributor Author

@RafaelSalguero RafaelSalguero commented Jul 9, 2020

@JLHwung please assign the issue to me, thanks!

existentialism pushed a commit that referenced this issue Jul 9, 2020
Fixes #11813) (#11816)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

3 participants
You can’t perform that action at this time.