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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Destructurisation transformation loses typescript types #14691

Closed
1 task
cainrus opened this issue Jun 24, 2022 · 5 comments 路 Fixed by #14694
Closed
1 task

[Bug]: Destructurisation transformation loses typescript types #14691

cainrus opened this issue Jun 24, 2022 · 5 comments 路 Fixed by #14694
Labels
area: typescript i: bug outdated A closed issue/PR that is archived due to age. Recommended to make a new issue

Comments

@cainrus
Copy link

cainrus commented Jun 24, 2022

馃捇

  • Would you like to work on a fix?

How are you using Babel?

@babel/cli

Input code

type Point = {
  x: number;
  y: number;
}

export function test({x, y}: Point) {
  return x * y;
}

Configuration file name

.babelrc.json

Configuration

{
  "plugins": [
    "@babel/plugin-transform-parameters",
    ["@babel/plugin-transform-destructuring", {
      "loose": true
    }],
    "@babel/plugin-syntax-typescript"
  ]
}

Current and expected behavior

Current output:

type Point = {
  x: number;
  y: number;
};
export function test(_ref) {
  let x = _ref.x,
      y = _ref.y;
  return x * y;
}

Expected output:

type Point = {
  x: number;
  y: number;
};
export function test(_ref: Point) {
  let x = _ref.x,
      y = _ref.y;
  return x * y;
}

Environment

System:
OS: macOS 12.2
Binaries:
Node: 16.14.2 - ~/.nvm/versions/node/v16.14.2/bin/node
Yarn: 3.2.1 - /usr/local/bin/yarn
npm: 8.5.0 - ~/.nvm/versions/node/v16.14.2/bin/npm
npmPackages:
@babel/cli: ^7.17.10 => 7.17.10
@babel/core: ^7.18.5 => 7.18.5
@babel/plugin-syntax-typescript: ^7.17.12 => 7.17.12
@babel/plugin-transform-destructuring: ^7.18.0 => 7.18.0

Possible solution

No response

Additional context

Reproduction repo

@babel-bot
Copy link
Collaborator

Hey @cainrus! 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

Out of curiosity, which tool/platform are you using that supports TS but not destructuring?

@cainrus
Copy link
Author

cainrus commented Jun 24, 2022

Out of curiosity, which tool/platform are you using that supports TS but not destructuring?

I want to use it with assemblyscript, to downgrade some neat modern syntax features to compatible with assemblyscript syntax (partial es2015 support)

@magic-akari
Copy link
Contributor

Is this the only case which type is losing?
I am willing to fix it, and I guess there are a lot of similar issues.

@cainrus
Copy link
Author

cainrus commented Jun 25, 2022

I guess there are a lot of similar issues.

Definitely a lot. I saw some more cases within my experiments (regenerated loops?)
But destruction helps a lot with boilerplate code.

@github-actions github-actions bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Sep 27, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 27, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: typescript i: bug outdated A closed issue/PR that is archived due to age. Recommended to make a new issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants