abstractMethod

View sourceabstractMethod<U extends ConstructorFn, T extends any>(item: T, baseConstructor: U, method: object): never

Throws a message explaining why an abstract method cannot be called for an item.

When item.constructor is exactly baseConstructor, the method is not callable because the base class is abstract. For any other constructor, the method is treated as unimplemented and should be overridden. The thrown value is a formatted string, not an Error instance.

Examples

class Base {
  run() {
    throw abstractMethod(this, Base, Base.prototype.run)
  }
}

class Child extends Base {}
new Child().run() // throws: the method is not implemented

Type Parameters

U extends ConstructorFn

T extends any

Parameters

NameDescriptionDefault
item

Instance on which the abstract method was called.

—
baseConstructor

Abstract base constructor to compare with the item’s constructor.

—
method

Abstract method whose name appears in the thrown message.

—

Throws

Always. Throws a “not callable” message when the item’s constructor is the base constructor; otherwise throws a “not implemented” message.

Returns

This function never returns.