You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
class A {
foo: number | string = 3;
}
class B extends A {
foo: string;
}
TypeScript with useDefineForClassFields: true gives the error TS2612: Property 'foo' will overwrite the base property in 'A'. If this is intentional, add an initializer. Otherwise, add a 'declare' modifier or remove the redundant declaration.
The typical fix is to change the class definition to:
class B extends A {
declare foo: string;
}
But Sucrase currently fails to parse the declare syntax, so that's an important prerequisite step.
The text was updated successfully, but these errors were encountered:
Fixes#536
We already completely remove uninitialized class fields for now, which agrees
with the `declare` behavior, so the only change needed here was to parse the
syntax without crashing. In the future, when we remove the class fields
transform, we'll need to distinguish declare vs non-declare fields.
Fixes#536
We already completely remove uninitialized class fields for now, which agrees
with the `declare` behavior, so the only change needed here was to parse the
syntax without crashing. In the future, when we remove the class fields
transform, we'll need to distinguish declare vs non-declare fields.
See https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html#the-usedefineforclassfields-flag-and-the-declare-property-modifier . As part of switching to fully spec-compliant class fields, a TS project will need to look for non-initialized class fields and make sure that the behavior is correct when using
define
. For example, with this code:TypeScript with
useDefineForClassFields: true
gives the errorTS2612: Property 'foo' will overwrite the base property in 'A'. If this is intentional, add an initializer. Otherwise, add a 'declare' modifier or remove the redundant declaration.
The typical fix is to change the class definition to:
But Sucrase currently fails to parse the
declare
syntax, so that's an important prerequisite step.The text was updated successfully, but these errors were encountered: