Skip to content

Babel emits properties for type-only properties in typescript classes #7997

@aaronjensen

Description

@aaronjensen

Bug Report

Current Behavior
When a class is defined like:

class Foo {
  bar!: string
}

And the typescript preset + class-properties is applied the generated code ends up including that property set to void 0 which differs from TypeScript.

class Foo {
  constructor() {
    this.bar = void 0;
  }

}

Input Code

https://github.com/aaronjensen/typescript-babel-repro

Expected behavior/code

It should not emit the property unless it has an assignment.

class Foo {
}

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

Note: loose is not important--the bug exists either way. It just simplifies the output.

{
  "presets": ["@babel/preset-typescript"],
  "plugins": [
    [
      "@babel/plugin-proposal-class-properties", { "loose": true }
    ]
  ]
}

Environment

  • Babel version(s): v7.0.0-beta.47
  • Node/npm version: Node 8/yarn 1.6.0
  • OS: macOS 10.13.4
  • Monorepo: no
  • How you are using Babel: repro cli, project loader

Metadata

Metadata

Assignees

No one assigned

    Labels

    i: questionoutdatedA 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