-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Closed
Labels
BugA bug in TypeScriptA bug in TypeScriptGood First IssueWell scoped, documented and has the green lightWell scoped, documented and has the green light
Milestone
Description
As explained in #2548, the following code is not correct when useDefineForClassFields: false, the default for targets before ES2021, or when target <= ES2020.
const x = 1
class C {
p = x
constructor(x: string) { }
}However, when useDefineForClassFields: true and target >= ES2021, there shouldn't be an error here.
Expected: No error 2301 on private p = x, and p: number
Actual: Error on private p = x and p: any
Edit: @fatcerberus pointed out that the error is only incorrect when useDefineForClassFields: true and target >= ES2021, because downlevel define for class fields still happens in the constructor.
robpalme and fatcerberus
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptGood First IssueWell scoped, documented and has the green lightWell scoped, documented and has the green light