Skip to content

TypeScript: the translation of parameter properties should be affected by the useDefineForClassFields configuration. #4421

@chirsz-ever

Description

@chirsz-ever

The following code:

class A {
    constructor(public x: number) {
    }
}

Since TypeScript 3.7, which added the useDefineForClassFields configuration1, it is translated into the following result with "useDefineForClassFields": true (playground), up to the latest version (5.9.3):

"use strict";
class A {
    x;
    constructor(x) {
        this.x = x;
    }
}

esbuild currently (0.27.4) generates the following code (playground):

class A {
  constructor(x) {
    this.x = x;
  }
}

I think we should stay consistent with TypeScript.

related: microsoft/TypeScript#55132

Footnotes

  1. https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html#the-usedefineforclassfields-flag-and-the-declare-property-modifier

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions