I have a subclass defined as follows:
customException.ts
/**
* Custom Error class.
*
* @class Error
* @extends {Error}
*/
class Error {
/**
* @type {string}
* @memberof Error
*/
message: string;
/**
* @type {boolean}
* @memberof Error
*/
isCustom: boolean;
/**
* @type {number}
* @memberof Error
*/
statusCode: number;
/**
* Constructor for creating a custom error.
*
* @param {string} message
* @param {number} statusCode
* @memberof Error
*/
constructor(message: string, statusCode: number) {
this.isCustom = true;
this.message = message;
this.statusCode = statusCode;
}
}
All other classes inherit from this base class as shown in:
import Error from customException
ForbiddenError extends Error
and we use it without any issues:
throw new ForbiddenError
However, why doesn't the base class Error need to be defined like:
class Error extends Error
, since there's no "extend" keyword used, how does it still exhibit the behavior of the parent class?