Skip to content

The behavior of class Parameter Properties changes with the es target #59589

Closed as not planned

Description

🔎 Search Terms

  • class
  • constructor parameter
  • useDefineForClassFields
  • initialization

📌 Related issues

🕗 Version & Regression Information

  • This changed between versions ______ and _______
  • This changed in commit or PR _______
  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about _________
  • I was unable to test this on prior versions because _______

⏯ Playground Link

https://www.typescriptlang.org/play/?useDefineForClassFields=true&target=7#code/PTAEAEBcEMCcHMCmkBcpEGcBMAGXAoECAVw0QBFEAzASwDtEAxAe1gGEAbaDDRmxDgBMMaSLGKJ8AYy49QAFQCeAB0QBlKbBrLIABTjQAtskSxdsZqtiR+GUAG98oZ6CJQMAWhrw6rSS9AqZmZQAF5QSAALGgwAOgAjOABuJxcpZjoMMWIpSFYACmVieI4aKVBE2DRoOkUASgdUgOd0zOYORFiOZnh8gCJaOmgODkU+gBoI6Lig5jqUgIBffGX8BgB3BRV1TW09A2NIU3NLUxtMfoA3YYk++aA

💻 Code

// @target: es2020
// @useDefineForClassFields: true
class TypeScriptParameterProperties {
    // @ts-ignore
    foo = this.bar;
    constructor(public bar: any) {
        console.log("finally", this.foo);
    }
}

new TypeScriptParameterProperties("value");
// @target: esnext
// @useDefineForClassFields: true
class TypeScriptParameterProperties {
    // @ts-ignore
    foo = this.bar;
    constructor(public bar: any) {
        console.log("finally", this.foo);
    }
}

new TypeScriptParameterProperties("value");

🙁 Actual behavior

Different compilation options will output different values.

es2020: "finally", "value"
esnext: "finally", undefined

🙂 Expected behavior

They should output the same value.

Additional information about the issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions