Skip to content

Regression: property used before initialization inside function #36441

Closed
@ajafff

Description

@ajafff

TypeScript Version: 3.8.0-dev.20200125

Search Terms:

Code

// @target: esnext
// @useDefineForClassFields. true
class C {
    bar = () => this.foo1 + this.foo2;
    foo1 = '';
    constructor(public foo2: string) {}
}

Expected behavior:

Accessing foo1 and foo2 should not be an error as the function is not immediately invoked and therefore the properties are initialized when accessed. This worked before #36425.

Actual behavior:

used before initialization error on this.foo1 and this.foo2

Playground Link: https://www.typescriptlang.org/play/?useDefineForClassFields=true&target=99&ts=3.8.0-dev.20200125&ssl=9&ssc=2&pln=5&pc=2#code/MYGwhgzhAEDC0G8BQ1XQEZgE7QLzQAoBKPAPmgBcALASwgDoAzAe2YEZoBqS2hl5gEwBuFGn4d8Ackki00YMwB2EClgCuwCsywEADmvQgawaPwEAuaCqw1FAcxIIAvkidA

Related Issues: #36425 @sandersn

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFix AvailableA PR has been opened for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions