fix(49719): Incorrect error 2301 when using ES standard class properties (#49725)

* fix(49719): omit TS2301 error with enabled usedefineforclassfields

* show error for target lower than esnext with useddefineforclassfields enabled

* change target from esnext to es2022
This commit is contained in:
Oleksandr T
2022-07-21 00:36:35 +03:00
committed by GitHub
parent 2f51a9e859
commit 5702941c2f
18 changed files with 232 additions and 2 deletions

View File

@@ -2191,7 +2191,7 @@ namespace ts {
// 1. When result is undefined, after checking for a missing "this."
// 2. When result is defined
function checkAndReportErrorForInvalidInitializer() {
if (propertyWithInvalidInitializer && !(getEmitScriptTarget(compilerOptions) === ScriptTarget.ESNext && useDefineForClassFields)) {
if (propertyWithInvalidInitializer && !(useDefineForClassFields && getEmitScriptTarget(compilerOptions) >= ScriptTarget.ES2022)) {
// We have a match, but the reference occurred within a property initializer and the identifier also binds
// to a local variable in the constructor where the code will be emitted. Note that this is actually allowed
// with ESNext+useDefineForClassFields because the scope semantics are different.

View File

@@ -141,7 +141,8 @@ namespace Harness {
"preserveConstEnums",
"skipLibCheck",
"exactOptionalPropertyTypes",
"useUnknownInCatchVariables"
"useDefineForClassFields",
"useUnknownInCatchVariables",
];
private fileName: string;
private justName: string;