Skip to content

Error not reported when class expression fails to implement abstract method #4655

Description

@jeffreymorlan
abstract class A { abstract foo(): void; }

class B extends A { }           // error, does not implement foo

var C = class extends A { };    // no error reported!
(new C).foo();                  // fails at runtime

If we look at the code in checker.ts that creates the relevant error:

// It is an error to inherit an abstract member without implementing it or being declared abstract.
// If there is no declaration for the derived class (as in the case of class expressions),
// then the class cannot be declared abstract.
if ( baseDeclarationFlags & NodeFlags.Abstract && (!derivedClassDecl || !(derivedClassDecl.flags & NodeFlags.Abstract))) {
    error(derivedClassDecl, Diagnostics.Non_abstract_class_0_does_not_implement_inherited_abstract_member_1_from_class_2,
        typeToString(type), symbolToString(baseProperty), typeToString(baseType));
}

In a class expression, derivedClassDecl is undefined - so the diagnostic is created, but not associated with a source location, so it doesn't get reported.

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFixedA PR has been merged for this issue

Type

No type
No fields configured for issues without a type.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions