Skip to content

Calling abstract methods inside abstract class constructor #9209

Closed
@prashaantt

Description

@prashaantt

TypeScript Version:

1.8.10

Code

export abstract class AbstractClass {
    constructor() {
        this.abstractMethod();
    }

    abstract abstractMethod(): void;
}

Output

"use strict";
var AbstractClass = (function () {
    function AbstractClass() {
        this.abstractMethod();
    }
    return AbstractClass;
}());
exports.AbstractClass = AbstractClass;

Question

Is there a situation where calling this.abstractMethod inside the constructor makes sense? I have accidentally hit this pattern and the class compiles successfully, but the resulting JavaScript obviously fails because this.abstractMethod is not a function.

Metadata

Metadata

Assignees

Labels

QuestionAn issue which isn't directly actionable in code

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions