Skip to content

Commit 36ee08e

Browse files
committed
fix: false positive for interface declared classes
1 parent 1a3b36b commit 36ee08e

File tree

4 files changed

+9
-65
lines changed

4 files changed

+9
-65
lines changed

src/compiler/checker.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,7 @@ import {
473473
isClassDeclaration,
474474
isClassElement,
475475
isClassExpression,
476+
isClassFieldAndNotAutoAccessor,
476477
isClassLike,
477478
isClassStaticBlockDeclaration,
478479
isCommaSequence,
@@ -31152,7 +31153,9 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
3115231153
}
3115331154
return false;
3115431155
}
31155-
if (!(flags & ModifierFlags.Static) && forEachProperty(prop, prop => prop.flags & SymbolFlags.Property)) {
31156+
// A class field cannot be accessed via super.* from a derived class.
31157+
// This is true for both [[Set]] (old) and [[Define]] (ES spec) semantics.
31158+
if (!(flags & ModifierFlags.Static) && prop.declarations?.some(isClassFieldAndNotAutoAccessor)) {
3115631159
if (errorNode) {
3115731160
error(errorNode,
3115831161
Diagnostics.Class_field_0_defined_by_the_parent_class_is_not_accessible_in_the_child_class_via_super,

src/compiler/utilitiesPublic.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1691,6 +1691,11 @@ export function isAutoAccessorPropertyDeclaration(node: Node): node is AutoAcces
16911691
return isPropertyDeclaration(node) && hasAccessorModifier(node);
16921692
}
16931693

1694+
/** @internal */
1695+
export function isClassFieldAndNotAutoAccessor(node: Node): boolean {
1696+
return node.parent && isClassLike(node.parent) && isPropertyDeclaration(node) && !hasAccessorModifier(node);
1697+
}
1698+
16941699
/** @internal */
16951700
export function isMethodOrAccessor(node: Node): node is MethodDeclaration | AccessorDeclaration {
16961701
switch (node.kind) {

tests/baselines/reference/esDecorators-classDeclaration-classSuper.2.errors.txt

Lines changed: 0 additions & 32 deletions
This file was deleted.

tests/baselines/reference/esDecorators-classExpression-classSuper.2.errors.txt

Lines changed: 0 additions & 32 deletions
This file was deleted.

0 commit comments

Comments
 (0)