abstract-class-error

3.0.0 • Public • Published

AbstractConstructError

An error designed for being thrown when a class is instantiated, an object created, or a method is not overridden that, was intended to be abstract.

import AbstractConstructError from 'abstract-class-error';

class AbstractParent {
    constructor() {
        if (new.target === AbstractParent) {
            throw new AbstractConstructError('Cannot construct class AbstractParent instances directly');
        }

        if (this.abstractMethod === AbstractParent.prototype.abstractMethod) {
            throw new AbstractConstructError('Method "abstractMethod" must be overridden in class AbstractParent');
        }
    }

    abstractMethod() {}
}

Feedback ✉️

Website 🌐

js@jacobsmith.tech

https://github.com/limeandcoconut

@limeandcoconut 🐦

Cheers!

License

ISC, see license for details.

Usage

NPM

License

ISC, see LICENSE.md for details.

Package Sidebar

Install

npm i abstract-class-error

Weekly Downloads

4

Version

3.0.0

License

ISC

Unpacked Size

6.48 kB

Total Files

7

Last publish

Collaborators

  • limeandcoconut