Skip to content

[Bug]: Declare fields and class-properties are incompatible #15530

Open

Description

@mxschmitt

💻

  • Would you like to work on a fix?

Abstract issue:

When using declare fields and class properties together, I can't make Babel work while TSC works.

How are you using Babel?

Babel CLI directly without any third party packages.

Input code

Repository: https://github.com/mxschmitt/declare-fields-class-properties-compatiblity

Steps:

  1. Clone the repo
  2. npm i
  3. npm run build

Observe two files: out-babel.js and out-tsc.js.

Configuration file name

No response

Configuration

See the repo with a minimal repro.

Current and expected behavior

Running out-tsc.js works fine but out-babel.js won't.

If I follow the recommendation to put @babel/plugin-proposal-class-properties after '@babel/plugin-transform-typescript' then the constructor order is messed up -> running the out-babel.js script throws.

If I put class-properties plugin before transform-typescript plugin, constructor order is ok, but declare fields won't work. -> build process fails and throws the following:

Environment

"dependencies": {
"@babel/cli": "^7.21.0",
"@babel/core": "^7.21.3",
"@babel/plugin-proposal-class-properties": "^7.18.6",
"@babel/plugin-transform-react-jsx": "^7.21.0",
"@babel/preset-env": "^7.20.2",
"@babel/preset-react": "^7.18.6",
"@babel/preset-typescript": "^7.21.0",
"typescript": "^5.0.2"
},
"devDependencies": {
"@types/node": "^18.15.11"
}

Node: v18.14.0
OS: macOS 13.3

Possible solution

No response

Additional context

No response

Activity

  1. babel-bot commented on Mar 30, 2023

    @babel-bot
    Collaborator

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

  2. self-assigned this
    on Mar 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions