abstract
Marks a class or member that cannot be instantiated or must be implemented.
Syntax
abstract class Name { abstract member(): Type } Examples
abstract class Shape {
abstract area(): number;
describe() {
return `area is ${this.area()}`;
}
}
class Square extends Shape {
constructor(private s: number) { super(); }
area() { return this.s * this.s; }
}
// new Shape(); // Error: cannot create instance of abstract class
Notes
An abstract class cannot be instantiated directly and may declare abstract
members with no implementation. Subclasses must implement every abstract
member. TypeScript also supports abstract construct signatures via
`abstract new (...) => T`.