Constructor

The `CommonErrors` constructor

CommonErrors()

Creates an instance of the errors storage with unique identification numbers.

Identification numbers given in the rest parameter id are used by the instance isAllowedId() method to check the existence of the specific id.

common-errors.class.ts
constructor(...id: Id[]) {
  Array.isArray(id) && (this.#id = new Set(id));
}

Parameters

...id:Id[]

A rest parameter of generic type variable Id indicates unique identification numbers under which the errors are stored in the object.

Example usage

// Example usage.
import { CommonErrors } from '@angular-package/error';

class CustomErrors<Id extends string> extends CommonErrors<Id> {
  constructor(...id: Id[]) {
    super(...id);
  }
}

// Initialize `CustomErrors` without defined `id`.
// Returns CustomErrors {} of CustomErrors<string>
new CustomErrors();

// Initialize `CustomErrors` with defined `id`.
// Returns CustomErrors {} of CustomErrors<"ERR1" | "ERR2" | "ERR3">
new CustomErrors('ERR1', 'ERR2', 'ERR3');

Last updated