Skip to content

[Bug]: Destructurisation transformation loses typescript types #14691

@cainrus

Description

@cainrus

💻

  • 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: typescriptoutdatedA closed issue/PR that is archived due to age. Recommended to make a new issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions