Skip to content

Incorrect "Property is used before its initialization" error with body-less arrow functions #45182

Closed
@jhnns

Description

@jhnns

Bug Report

🔎 Search Terms

Property is used before its initialization
arrow function
body
property
initializer
constructor parameter
useDefineForClassFields

🕗 Version & Regression Information

  • >= 3.8.3
  • Also nightly
  • This changed between versions 3.7.5 and 3.8.3

⏯ Playground Link

Playground link with relevant code

💻 Code

class A {
    value = 1;
}

class B {
    constructor(private a: A) {}

    // Shows "Property 'a' is used before its initialization"
    getAValue = () => this.a.value;
    
    // No error when there's a function body
    // getAValue = () => { return this.a.value };
}

useDefineForClassFields must be true

🙁 Actual behavior

With useDefineForClassFields: true there's an error when the arrow function has no body

🙂 Expected behavior

There should be no error

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptHelp WantedYou can do this

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions