# Introduction

@angular-package/error

## angular-package/error

The error package contains a typical, range, type, and validation error object extended by the javascript error. Their message is built from the required problem, solution to a problem, and unique identification number on the error message template. Individual errors have additional message parameters corresponding to the functionality. Range error has an additional minimum and maximum range that causes an error to be thrown or not thrown, and type error the type.

The package contains prepared objects to manage the errors of the same type and multiple identification numbers, and their purpose is to set and throw errors under the given identification.

Let's see what are the benefits.


# ❤ Benefits

<details>

<summary>Problem and its solution</summary>

<mark style="color:green;">**✓**</mark> The error message is **divided** into the **problem** and its **solution**.

<mark style="color:green;">**✓**</mark> An error has the **problem**.

<mark style="color:green;">**✓**</mark> An error has a **solution** to the described problem.

<mark style="color:green;">**✓**</mark> There is no error without a **potential solution**.

</details>

<details>

<summary>Unique identification</summary>

<mark style="color:green;">**✓**</mark> An error can have **unique identification** of generic type variable.

<mark style="color:green;">**✓**</mark>**&#x20;Unique identification** numbers enforce the **systematization** of application errors.

<mark style="color:green;">**✓**</mark> Enforcement of systematization produces **thoughtful application**.

</details>

<details>

<summary>Template</summary>

<mark style="color:green;">**✓**</mark> Template with **replaceable variable** tags `{problem}` `{fix}` `{id}` `{min}` `{max}` `{type}` `{link}`.

<mark style="color:green;">**✓**</mark> Each error can be thrown with a **different** template.

</details>

<details>

<summary>Range error</summary>

<mark style="color:green;">**✓**</mark> An error contains additional parameters to indicate the minimum and maximum range that causes an error to be or not to be thrown.

</details>

<details>

<summary>Type error</summary>

<mark style="color:green;">**✓**</mark> An error contains an additional parameter to indicate the type that causes an error to be or not to be thrown.

</details>

<details>

<summary>Custom error</summary>

<mark style="color:green;">**✓**</mark> Create custom errors that feature: message divided into problem and fix, unique identification, and the template by extending the abstract object.

</details>

<details>

<summary>Storage to manage errors</summary>

<mark style="color:green;">**✓**</mark> The objects to **manage** errors of the same type of multiple unique identification numbers.

<mark style="color:green;">**✓**</mark>**&#x20;Set** the error at a selected number from the group of unique identification numbers.

<mark style="color:green;">**✓**</mark>**&#x20;Throw** an error with a selected number from the group of unique identification numbers.

<mark style="color:green;">**✓**</mark>**&#x20;Get** a single error of a selected number from the group of unique identification numbers.

<mark style="color:green;">**✓**</mark>**&#x20;Get** all set errors.

</details>


# General concepts

Explanation of common terms for all packages.

### ⚠

The warning sign indicates the element is **not** **available**.

### ★

The element starred as most **useful**.

### **Checks**

It's to **check** the provided value to be the same as **expected**.

### Type guard (constrain)

Constrains the parameter type to not let input unexpected value in the code editor.

### **Guard**

It's a **combination** of both above, **constrains** the type of the parameter in the **code editor**, and checks its provided argument.

### **Defines**

Returns defined value from a method of an object.

Defines new value in an object and returns a defined value.

### **Gets**

Returns a value from an object.

### **Sets**

Adds or updates an element with a specified key and a value to an object and returns an object.

### Intuitive

Having the ability to know or understand things without any proof or evidence. E.g. some of the accessor names indicate directly its role.

### General

Relating to the main or major parts of something rather than the details. E.g. some of the accessor names don't indicate the specific role in the object.

{% embed url="<https://docs.angular-package.dev/v/designing/definitions>" %}
More definitions
{% endembed %}


# Skeleton

The package was generated by the [library skeleton](https://github.com/angular-package/skeleton) which was generated with [Angular CLI](https://github.com/angular/angular-cli) version 13.0.0.&#x20;

Copy package to the `packages/error` folder of the [library skeleton](https://github.com/angular-package/skeleton) then run the commands below.

### Code scaffolding

Run `ng generate component component-name --project error` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module --project error`.

> Note: Don't forget to add `--project error` or else it will be added to the default project in your `angular.json` file.

### Build

Run `ng build error` to build the project. The build artifacts will be stored in the `dist/error` directory.

### **Publishing**

After building your library with `ng build error`, go to the dist folder `cd dist/error` and run `npm publish`.

### **Running unit tests**

Before the test can be performed install [`@angular-package/testing`](https://github.com/angular-package/testing) and [`@angular-package/type`](https://type.angular-package.dev/) with command:&#x20;

```bash
npm i @angular-package/testing @angular-package/type --no-save
```

Run `ng test error` to execute the unit tests via [Karma](https://karma-runner.github.io).

### Further help

To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI Overview and Command Reference](https://angular.io/cli) page.


# Installation

The package can be installed into your project via [NPM](https://www.npmjs.com/), or [yarn](https://yarnpkg.com/getting-started/install).

{% tabs %}
{% tab title="npm" %}

```bash
npm install @angular-package/error --save
```

{% endtab %}

{% tab title="yarn" %}

```
yarn add @angular-package/error
```

{% endtab %}
{% endtabs %}


# Public API

@angular-package/error

Public features that can be imported.

```typescript
import {
  // Class.
  CommonError,
  CommonErrors,
  Error,
  Errors,
  RangeError,
  RangeErrors,
  TypeError,
  TypeErrors,
  ValidationError,
  ValidationErrors
} from '@angular-package/error';
```

### `CommonError`

The [`CommonError`](/draft-5/commonerror/overview) abstract object to throw an [identified](/draft-5/getting-started/basic-concepts#identification) error with a [solution](/draft-5/getting-started/basic-concepts#fix) to the described [problem](/draft-5/getting-started/basic-concepts#problem), additional [type](/draft-5/getting-started/basic-concepts#type), and [range](/draft-5/getting-started/basic-concepts#range) built on the [template](/draft-5/getting-started/basic-concepts#template).

### `CommonErrors`

The [`CommonErrors`](/draft-5/commonerrors/overview) object represents the storage of errors with [unique identification](/draft-5/getting-started/basic-concepts#unique-identification) numbers.

### `Error`

The [`Error`](/draft-5/error/overview) object is an extension of the [`CommonError`](/draft-5/commonerror/overview) class and is thrown when a runtime error occurs with a [message](https://app.gitbook.com/s/23iV8ygEQUrhqw7I3D8g/~/changes/lXvTfsmAkHoNRKsQjxlq/commonerror/accessors/get-message) built from a [solution](https://app.gitbook.com/s/23iV8ygEQUrhqw7I3D8g/~/changes/lXvTfsmAkHoNRKsQjxlq/commonerror/accessors/get-fix) to the described [problem](https://app.gitbook.com/s/23iV8ygEQUrhqw7I3D8g/~/changes/lXvTfsmAkHoNRKsQjxlq/commonerror/accessors/get-problem) but with additional identification, on the [template](https://app.gitbook.com/s/23iV8ygEQUrhqw7I3D8g/~/changes/lXvTfsmAkHoNRKsQjxlq/commonerror/accessors/get-template).

### `Errors`

The [`Errors`](/draft-5/errors/overview) is an extension of the [`CommonErrors`](/draft-5/commonerrors/overview) object that represents multiple identification numbers under which the errors of the [`Error`](/draft-5/error/overview) type are prepared to throw.

### `RangeError`

The [`RangeError`](/draft-5/rangeerror/overview) object is an extension of the [`CommonError`](/draft-5/commonerror/overview) class and is thrown when a value is not in the set or range of allowed values with the message built from the described problem and its solution, optional explicit identification and minimum/maximum range on the given or stored template.

### `RangeErrors`

The [`RangeErrors`](/draft-5/rangeerrors/overview) is an extension of the [`CommonErrors`](/draft-5/commonerrors/overview) object that represents multiple identification numbers under which the errors of the [`RangeError`](/draft-5/rangeerror/overview) type are prepared to throw.

### `TypeError`

The [`TypeError`](/draft-5/typeerror/overview) object is an extension of the [`CommonError`](/draft-5/commonerror/overview) class and is thrown when an operation could not be performed, typically(but not exclusively) when a value is not of the expected type, with the [message](/draft-5/commonerror/accessors/get-message) built from the described problem and its solution, optional an explicit identification and type, on the given or stored template.

### `TypeErrors`

The [`TypeErrors`](/draft-5/typeerrors/overview) is an extension of the [`CommonErrors`](/draft-5/commonerrors/overview) object that represents multiple identification numbers under which the errors of the [`TypeError`](/draft-5/typeerror/overview) type are prepared to throw.

### `ValidationError`

The [`ValidationError`](/draft-5/validationerror/overview) object is an extension of the [`CommonError`](/draft-5/commonerror/overview) class and is thrown when an operation could not be performed despite proper type(but not exclusively) with the [message](/draft-5/commonerror/accessors/get-message) built from the described problem and its solution, along with additional identification on the given or stored template.

### `ValidationErrors`

The [`ValidationErrors`](/draft-5/validationerrors/overview) is an extension of the [`CommonErrors`](/draft-5/commonerrors/overview) object that represents multiple identification numbers under which the errors of the [`ValidationError`](/draft-5/validationerror/overview) type are prepared to throw.


# Basic concepts

The error package basic concepts

### Fix

A potential solution to the described [problem](#problem).

### Link

A link that refers to the potential solution of the problem.

### Message

The error message that is built from the required problem, fix and optional range, type on the template.

### Problem

The problem that causes an error to be thrown.

### Range

The minimum and maximum range that causes the [`RangeError`](/draft-5/rangeerror/overview) to be or not to be thrown.

### Template

A template for the message error with replaceable variable tags.

### Type

The type that causes the [`TypeError`](/draft-5/typeerror/overview) to be or not to be thrown.

### Unique identification

The unique identification of the error help finds a solution. It's based on a generic type variable to get the exact type.


# Overview

The \`CommonError\` abstract object to throw an identified error with a solution to the described problem

## `CommonError {}`

The `CommonError` abstract object to throw an [identified](/draft-5/getting-started/basic-concepts#identification) error with a [solution](/draft-5/getting-started/basic-concepts#fix) to the described [problem](/draft-5/getting-started/basic-concepts#problem), additional [type](/draft-5/getting-started/basic-concepts#type), and [range](/draft-5/getting-started/basic-concepts#range) built on the [template](/draft-5/getting-started/basic-concepts#template).

{% embed url="<https://github.com/angular-package/error/blob/main/src/lib/common-error.class.ts>" %}
`common-error.class.ts`
{% endembed %}

### Accessors

|                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |                                                                                                                                                                                                                                                                                                                                                                                   |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| <p><strong>public get</strong> <a href="/pages/59loEPLx3eMsMq3XEWAP"><strong>fix()</strong></a><strong>:</strong> <mark style="color:green;">string</mark><br>The <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/get"><code>get</code></a> accessor obtains a possible <a href="/pages/6Nle1uMltWSb2uh6hgTQ#fix">solution</a> to the described <a href="/pages/LxHtOb8sW6C9DrVZpyJ2">problem</a> by returning the <a href="/pages/bM02xNqvdJvIfZJuzFc6"><code>#fix</code></a> property of a specified object</p>                                                                                                                               |                                                                                                                                                                                                                                                                                                                                                                                   |
| <p><strong>public get</strong> <a href="/pages/vXJtO6FJrof8aEObMAcU"><strong>id()</strong></a><strong>:</strong> <mark style="color:green;">Id</mark>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                | <mark style="color:green;">undefined</mark><br>The <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/get"><code>get</code></a> accessor gets the error <a href="/pages/6Nle1uMltWSb2uh6hgTQ#identification">identification</a> by returning the <a href="/pages/sM1pw7PS84C8cmqys4wZ"><code>#id</code></a> property of a specified object.</p> |
| <p><strong>public get</strong> <a href="/pages/GQRdEFvOHDqfnGJ51NkB"><strong>link()</strong></a><strong>:</strong> <mark style="color:green;">string</mark>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          | <mark style="color:green;">undefined</mark><br>The <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/get"><code>get</code></a> accessor gets the link(to read more about the thrown error) by returning the <a href="/pages/T7CzWe5vgWUYvAmOLUPa"><code>#link</code></a> property of a specified object.</p>                                   |
| <p><strong>public get</strong> <a href="/pages/UAsNmVmOuYGxNypELFFh"><strong>message()</strong></a><strong>:</strong> <mark style="color:green;">string</mark><br>The <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/get"><code>get</code></a> accessor gets the error <a href="/pages/6Nle1uMltWSb2uh6hgTQ#message">message</a> by returning the parent <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/message"><code>message</code></a> property of the <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error"><code>Error</code></a> object.</p> |                                                                                                                                                                                                                                                                                                                                                                                   |
| <p><strong>public get</strong> <a href="/pages/LxHtOb8sW6C9DrVZpyJ2"><strong>problem()</strong></a><strong>:</strong> <mark style="color:green;">string</mark><br>The <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/get"><code>get</code></a> accessor gets the <a href="/pages/6Nle1uMltWSb2uh6hgTQ#problem">problem</a> by returning the <a href="/pages/ni1YTHvL07t1jeocuGux"><code>#problem</code></a> property of a specified object.</p>                                                                                                                                                                                                |                                                                                                                                                                                                                                                                                                                                                                                   |
| <p><strong>public get</strong> <a href="/pages/GF0yfhKsp9WzRTAHqFDt"><strong>template()</strong></a><strong>:</strong> <mark style="color:green;">string</mark><br>The <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/get"><code>get</code></a> accessor gets the <a href="/pages/6Nle1uMltWSb2uh6hgTQ#template">template</a> of the error message by returning the <a href="/pages/VT4SwlV0NwAnpvm5q6hg"><code>#template</code></a> property of a specified object.</p>                                                                                                                                                                       |                                                                                                                                                                                                                                                                                                                                                                                   |

### Properties

|                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| <p><strong>public static</strong> <a href="/pages/akE6vknq8khSYhbok2vb"><strong>template</strong></a><strong>:</strong> <mark style="color:green;">string</mark><br>A template of the error message of <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String"><code>string</code></a> type with the replaceable <a href="/pages/BbVb9Mj2Y9veAqrtKz61#problem"><code>{problem}</code></a>, <a href="/pages/BbVb9Mj2Y9veAqrtKz61#fix"><code>{fix}</code></a> and optional <a href="/pages/BbVb9Mj2Y9veAqrtKz61#id"><code>{id}</code></a>, <code>{link}</code>, <a href="/pages/BbVb9Mj2Y9veAqrtKz61#max"><code>{max}</code></a>, <a href="/pages/BbVb9Mj2Y9veAqrtKz61#min"><code>{min}</code></a>, <a href="/pages/BbVb9Mj2Y9veAqrtKz61#type"><code>{type}</code></a> tags.</p>                                                                  |
| <p><a href="/pages/bM02xNqvdJvIfZJuzFc6"><strong>#fix</strong></a><strong>:</strong> <mark style="color:green;">string</mark><br>A privately stored possible solution to the described <a href="/pages/6Nle1uMltWSb2uh6hgTQ#problem">problem</a> of a <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String"><code>string</code></a> type.</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| <p><a href="/pages/sM1pw7PS84C8cmqys4wZ"><strong>#id?</strong></a><strong>:</strong> <mark style="color:green;">Id</mark><br>A privately stored unique <a href="/pages/6Nle1uMltWSb2uh6hgTQ#identification">identification</a> of the described <a href="/pages/6Nle1uMltWSb2uh6hgTQ#problem">problem</a> of generic type variable <a href="/pages/PY4nixy9omXSectfeNl5#wrap-opening"><code>Id</code></a>.</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
| <p><a href="/pages/T7CzWe5vgWUYvAmOLUPa"><strong>#link?</strong></a><strong>:</strong> <mark style="color:green;">string</mark><br>The optional privately stored link of <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String"><code>string</code></a> type redirects to read more about the thrown error.</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| <p><a href="/pages/ni1YTHvL07t1jeocuGux"><strong>#problem</strong></a><strong>:</strong> <mark style="color:green;">string</mark><br>A privately stored <a href="/pages/6Nle1uMltWSb2uh6hgTQ#problem">problem</a> of a <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String"><code>string</code></a> type.</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| <p><a href="/pages/VT4SwlV0NwAnpvm5q6hg"><strong>#template</strong></a><strong>:</strong> <mark style="color:green;">string</mark><br>A <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string-type</a> privately stored <a href="/pages/6Nle1uMltWSb2uh6hgTQ#template">template</a> of the error <a href="/pages/6Nle1uMltWSb2uh6hgTQ#message">message</a> that contains replaceable required <a href="/pages/BbVb9Mj2Y9veAqrtKz61#fix"><code>{fix}</code></a>, <a href="/pages/BbVb9Mj2Y9veAqrtKz61#problem"><code>{problem}</code></a> and optional <a href="/pages/BbVb9Mj2Y9veAqrtKz61#id"><code>{id}</code></a>, <a href="/pages/BbVb9Mj2Y9veAqrtKz61#max"><code>{max}</code></a>, <a href="/pages/BbVb9Mj2Y9veAqrtKz61#min"><code>{min}</code></a>, <a href="/pages/BbVb9Mj2Y9veAqrtKz61#type"><code>{type}</code></a> tags.</p> |

### Methods

|                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| <p><strong>protected static</strong> <a href="/pages/KhI7uCqLCibWKkF1fp1b"><strong>defineMessage()</strong></a><strong>:</strong> <mark style="color:green;">string</mark><br>The static "<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals">tag</a>" method builds from the given <a href="/pages/KhI7uCqLCibWKkF1fp1b#...values-any"><code>values</code></a> the error message of a <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String"><code>string</code></a> type on the template.</p> |
| <p><strong>protected static</strong> <a href="/pages/EVnsL3y0PxCd21o8K9N0"><strong>isError()</strong></a><strong>: value is</strong> <mark style="color:green;">CommonError</mark><<mark style="color:green;">Id</mark>><br>Checks whether the <a href="/pages/EVnsL3y0PxCd21o8K9N0#value-any"><code>value</code></a> of any type is a <code>this</code> instance of any or the given <a href="/pages/EVnsL3y0PxCd21o8K9N0#id-id">identification</a>.</p>                                                                                                                            |


# Generic type variables

The \`CommonError\` object generic type variables

## `CommonError<`<mark style="color:green;background-color:green;">`Id`</mark>`>`

#### <mark style="color:green;">`Id`</mark>`extends`[<mark style="color:green;">`string`</mark>](https://www.typescriptlang.org/docs/handbook/basic-types.html#string)

​A generic type variable constrained by the [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String), by default of the value **captured** from the provided [`id`](/draft-5/commonerror/constructor#id-id) indicates the identification type of a new [`CommonError`](/draft-5/commonerror/overview) instance.

{% code title="common-error.class.ts" %}

```typescript
abstract class CommonError<
  Id extends string // <--- Declare generic type variable Id.
> extends Error {
  ...
  constructor(
    problem: string,
    fix: string,
    id?: Id, // <--- Capture generic type variable Id.
    template = CommonError.template,
    additional?: { link?: string; max?: number; min?: number; type?: string }
  ) { ... }
  ...
}
```

{% endcode %}


# Constructor

The \`CommonError\` object constructor

## `CommonError()`

Creates an error instance with the [message](/draft-5/commonerror/accessors/get-message) built from the given [problem](#problem-string), its [solution](#fix-string), optional [type](#additional-link-string-min-number-max-number-type-string), [range](#additional-link-string-min-number-max-number-type-string), an explicit [identification](#id-id) on the supplied or stored [template](#template-string-commonerror.template).

{% code title="common-error.class.ts" %}

```typescript
constructor(
  problem: string,
  fix: string,
  id?: Id,
  template = CommonError.template,
  additional?: { link?: string; max?: number; min?: number; type?: string }
) {
  super(
    CommonError.defineMessage`${problem}${fix}${id}${template}${additional}`
  );
  this.#fix = fix;
  this.#id = id;
  this.#link = additional?.link;
  this.#problem = problem;
  this.#template = template;
}
```

{% endcode %}

### Parameters

#### `problem:`[<mark style="color:green;">`string`</mark>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)

Description of the problem of a [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) type.

#### `fix:`[<mark style="color:green;">`string`</mark>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)

A solution to the given [`problem`](#problem-string) of a [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) type.

#### `id?:`[<mark style="color:green;">`Id`</mark>](/draft-5/commonerror/generic-type-variables#wrap-opening)

Optional unique [identification](/draft-5/getting-started/basic-concepts#identification) to the given [`problem`](#problem-string) of generic type variable [`Id`](/draft-5/commonerror/generic-type-variables#commonerror-less-than-id-greater-than).

#### `template:`[<mark style="color:green;">`string`</mark>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)`=`<mark style="color:green;">`CommonError`</mark>`.template`

A template of error message with the replaceable [`{problem}`](#problem), [`{fix}`](#fix) and optional [`{id}`](#id), `{link}`, [`{max}`](#max), [`{min}`](#min) and [`{type}`](#type) tags.

{% hint style="info" %}
By default, the value is equal to the static property [`template`](/draft-5/commonerror/properties/static-template).
{% endhint %}

#### `additional: {link?:`[<mark style="color:green;">`string`</mark>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)`; min?:`[<mark style="color:green;">`number`</mark>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)`; max?:`[<mark style="color:green;">`number`</mark>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)`; type?:`[<mark style="color:green;">`string`</mark>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)`}`

An optional [`object`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object) consists of optional `link`, `min`, `max`, and `type` properties to define the error [`message`](/draft-5/commonerror/accessors/get-message).&#x20;

`link` - The link to read more about the thrown error replaceable on the given [`template`](#template-string-commonerror.template) as [`{link}`](/draft-5/commonerror/properties/static-template#link) tag.\
`max`   - The maximum number replaceable on the given [`template`](#template-string-commonerror.template) as [`{max}`](/draft-5/commonerror/properties/static-template#max) tag.\
`min`   - The minimum number is replaceable on the given [`template`](#template-string-commonerror.template) as [`{min}`](/draft-5/commonerror/properties/static-template#min) tag.\
`type` - The type indicates the expected type that isn't throwing an error or the not expected type that is throwing an error replaceable on the given [`template`](#template-string-commonerror.template) as the [`{type}`](/draft-5/commonerror/properties/static-template#type) tag.

## Example usage

### Basic usage

Example with the given required `problem` and `fix`.

```typescript
// Example usage.
import { CommonError } from '@angular-package/error';

// Create `TestError` to extend.
class TestError<Id extends string> extends CommonError<Id> {}

// Uncaught Error: Problem: problem => Fix: fix
throw new TestError(
  'problem',
  'fix'
);
```

### `id`

Example with the given `id`.

```typescript
// Example usage.
import { CommonError } from '@angular-package/error';

// Create `TestError` to extend.
class TestError<Id extends string> extends CommonError<Id> {}

// Uncaught Error: Problem(AE:427): problem => Fix: fix
throw new TestError(
  'problem',
  'fix',
  '(AE:427)' // <--- Parameter `id`.
);
```

### `id`, `template`

Example with the given `id` and `template`.

```typescript
// Example usage.
import { CommonError } from '@angular-package/error';

// Create `TestError` to extend.
class TestError<Id extends string> extends CommonError<Id> {}

// Uncaught Error: problem(AE:427). fix
throw new TestError(
  'problem',
  'fix',
  'AE:427', // <--- Parameter `id`
  '{problem}({id}). {fix}' // <--- Parameter `template`
);
```

### `id`, `template`, `additional{ min }`

Example with the given `id`, `template` and property `min` of `additional`.

```typescript
// Example usage.
import { CommonError } from '@angular-package/error';

// Create `TestError` to extend.
class TestError<Id extends string> extends CommonError<Id> {}

// Uncaught Error: (AE:427)Age must be above 9. Provide age more than 9
throw new TestError(
  'Age must be above ', // Problem
  'Provide age more than ', // Fix
  'AE:427', // Identification
  '({id}){problem}{min}. {fix}{min}', // Template
  { min: 9 } // Additional
);
```

### `id`, `template`, `additional{ min, max }`&#x20;

Example with the given `id`, `template` and property `min` and `max` of `additional`.

```typescript
// Example usage.
import { CommonError } from '@angular-package/error';

// Create `TestError` to extend.
class TestError<Id extends string> extends CommonError<Id> {}

// Uncaught Error: (AE:427)The `age` parameter is 45. Provided `age` must be between 9 and 12
throw new TestError(
  'The `age` parameter is 45.', // Problem
  'Provided `age` must be', // Fix
  'AE:427', // Identification
  '({id}){problem} {fix} between {min} and {max}', // Template
  { min: 9, max: 12 } // Additional
);
```

### `id`, `template`, `additional{ min, max, type }`&#x20;

Example with the given `id`, `template`, property `min`, `max` and `type` of `additional`.

```typescript
// Example usage.
import { CommonError } from '@angular-package/error';

// Create `TestError` to extend.
class TestError<Id extends string> extends CommonError<Id> {}

// Uncaught Error: (AE:427)The `age` parameter is not a number. Provided `age` must be a  number between 9 and 12.
throw new TestError(
  'The `age` parameter is not a', // Problem
  'Provided `age` must be a ', // Fix
  'AE:427', // Identification
  '({id}){problem} {type}. {fix} {type} between {min} and {max}.', // Template
  { min: 9, max: 12, type: 'number' } // Additional
);
```


# Accessors

The \`CommonError\` object accessors

|                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |                                                                                                                                                                                                                                                                                                                                                                                   |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| <p><strong>public get</strong> <a href="/pages/59loEPLx3eMsMq3XEWAP"><strong>fix()</strong></a><strong>:</strong> <mark style="color:green;">string</mark><br>The <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/get"><code>get</code></a> accessor obtains a possible <a href="/pages/6Nle1uMltWSb2uh6hgTQ#fix">solution</a> to the described <a href="/pages/LxHtOb8sW6C9DrVZpyJ2">problem</a> by returning the <a href="/pages/bM02xNqvdJvIfZJuzFc6"><code>#fix</code></a> property of a specified object</p>                                                                                                                               |                                                                                                                                                                                                                                                                                                                                                                                   |
| <p><strong>public get</strong> <a href="/pages/vXJtO6FJrof8aEObMAcU"><strong>id()</strong></a><strong>:</strong> <mark style="color:green;">Id</mark>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                | <mark style="color:green;">undefined</mark><br>The <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/get"><code>get</code></a> accessor gets the error <a href="/pages/6Nle1uMltWSb2uh6hgTQ#identification">identification</a> by returning the <a href="/pages/sM1pw7PS84C8cmqys4wZ"><code>#id</code></a> property of a specified object.</p> |
| <p><strong>public get</strong> <a href="/pages/GQRdEFvOHDqfnGJ51NkB"><strong>link()</strong></a><strong>:</strong> <mark style="color:green;">string</mark>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          | <mark style="color:green;">undefined</mark><br>The <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/get"><code>get</code></a> accessor gets the link(to read more about the thrown error) by returning the <a href="/pages/T7CzWe5vgWUYvAmOLUPa"><code>#link</code></a> property of a specified object.</p>                                   |
| <p><strong>public get</strong> <a href="/pages/UAsNmVmOuYGxNypELFFh"><strong>message()</strong></a><strong>:</strong> <mark style="color:green;">string</mark><br>The <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/get"><code>get</code></a> accessor gets the error <a href="/pages/6Nle1uMltWSb2uh6hgTQ#message">message</a> by returning the parent <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/message"><code>message</code></a> property of the <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error"><code>Error</code></a> object.</p> |                                                                                                                                                                                                                                                                                                                                                                                   |
| <p><strong>public get</strong> <a href="/pages/LxHtOb8sW6C9DrVZpyJ2"><strong>problem()</strong></a><strong>:</strong> <mark style="color:green;">string</mark><br>The <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/get"><code>get</code></a> accessor gets the <a href="/pages/6Nle1uMltWSb2uh6hgTQ#problem">problem</a> by returning the <a href="/pages/ni1YTHvL07t1jeocuGux"><code>#problem</code></a> property of a specified object.</p>                                                                                                                                                                                                |                                                                                                                                                                                                                                                                                                                                                                                   |
| <p><strong>public get</strong> <a href="/pages/GF0yfhKsp9WzRTAHqFDt"><strong>template()</strong></a><strong>:</strong> <mark style="color:green;">string</mark><br>The <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/get"><code>get</code></a> accessor gets the <a href="/pages/6Nle1uMltWSb2uh6hgTQ#template">template</a> of the error message by returning the <a href="/pages/VT4SwlV0NwAnpvm5q6hg"><code>#template</code></a> property of a specified object.</p>                                                                                                                                                                       |                                                                                                                                                                                                                                                                                                                                                                                   |


# get fix()

The get accessor obtains a possible solution to the described problem

## `CommonError.prototype.fix`

The [`get`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/get) accessor obtains a possible [solution](/draft-5/getting-started/basic-concepts#fix) to the described [problem](/draft-5/commonerror/accessors/get-problem) by returning the [`#fix`](/draft-5/commonerror/properties/fix) property of a specified object.

{% code title="common-error.class.ts" %}

```typescript
public get fix(): string {
  return this.#fix;
}
```

{% endcode %}

### Return type

#### [<mark style="color:green;">`string`</mark>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)

### Returns

The **return value** is the fix of a [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) type.

## Example usage

```typescript
// Example usage.
import { CommonError } from '@angular-package/error';

// Extend the `CommonError` class.
class TestError<Id extends string> extends CommonError<Id> {}

// Returns "Fix accessor."
new TestError('problem', 'Fix accessor.', '(AE:427)').fix;
```


# get id()

The get accessor gets the error identification

## `CommonError.prototype.id`

The [`get`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/get) accessor gets the error [identification](/draft-5/getting-started/basic-concepts#identification) by returning the [`#id`](/draft-5/commonerror/properties/id) property of a specified object.

{% code title="common-error.class.ts" %}

```typescript
public get id(): Id | undefined {
  return this.#id;
}
```

{% endcode %}

### Return type

#### [<mark style="color:green;">`Id`</mark>](/draft-5/commonerror/generic-type-variables#commonerror-less-than-id-greater-than)`|`[<mark style="color:green;">`undefined`</mark>](https://www.typescriptlang.org/docs/handbook/basic-types.html#null-and-undefined)

The **return type** is the generic type variable [`Id`](/draft-5/commonerror/generic-type-variables#commonerror-less-than-id-greater-than) or [`undefined`](https://www.typescriptlang.org/docs/handbook/basic-types.html#null-and-undefined).

### Returns

The **return value** is the error [identification](/draft-5/getting-started/basic-concepts#identification) of the generic type variable [`Id`](/draft-5/commonerror/generic-type-variables#commonerror-less-than-id-greater-than) or [`undefined`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined).

## Example usage

```typescript
// Example usage.
import { CommonError } from '@angular-package/error';

// Extend the `CommonError` class.
class TestError<Id extends string> extends CommonError<Id> {}

// Returns "(AE:427)".
new TestError('problem', 'Fix accessor.', '(AE:427)').id;
```


# get link()

The get accessor gets the link(to read more about the thrown error)

## `CommonError.prototype.link`

The [`get`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/get) accessor gets the link(to read more about the thrown error) by returning the [`#link`](/draft-5/commonerror/properties/link) property of a specified object.

{% code title="common-error.class.ts" %}

```typescript
public get link(): string | undefined {
  return this.#link;
}
```

{% endcode %}

### Return type

#### [<mark style="color:green;">`string`</mark>](https://www.typescriptlang.org/docs/handbook/basic-types.html#string)`|`[<mark style="color:green;">`undefined`</mark>](https://www.typescriptlang.org/docs/handbook/basic-types.html#null-and-undefined)

The **return type** is a [`string`](https://www.typescriptlang.org/docs/handbook/basic-types.html#string) type or [`undefined`](https://www.typescriptlang.org/docs/handbook/basic-types.html#null-and-undefined).

### Returns

The **return value** is the link of a [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) type or [`undefined`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined).

## Example usage

```typescript
// Example usage.
import { CommonError } from '@angular-package/error';

// Extend the `CommonError` class.
class TestError<Id extends string> extends CommonError<Id> {}

// Returns "http://duckduckgo.com".
new TestError('problem', 'Fix accessor.', '(AE:427)', undefined, {
  link: 'http://duckduckgo.com',
}).link;
```


# get message()

The get accessor gets the error message

## `CommonError.prototype.message`

The [`get`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/get) accessor gets the error [message](/draft-5/getting-started/basic-concepts#message) by returning the parent [`message`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/message) property of the [`Error`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error) object.

{% code title="common-error.class.ts" %}

```typescript
public get message(): string {
  return super.message;
}
```

{% endcode %}

### Return type

#### [<mark style="color:green;">`string`</mark>](https://www.typescriptlang.org/docs/handbook/basic-types.html#string)

### Returns

The **return value** is the error [message](/draft-5/getting-started/basic-concepts#message) of a [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) type.

## Example usage

```typescript
// Example usage.
import { CommonError } from '@angular-package/error';

// Extend the `CommonError` class.
class TestError<Id extends string> extends CommonError<Id> {}

// Returns "Problem(AE:427): Problem accessor. => Fix: Fix accessor.".
new TestError('Problem accessor.', 'Fix accessor.', '(AE:427)').message;
```


# get problem()

The get accessor gets the problem

## `CommonError.prototype.problem`

The [`get`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/get) accessor gets the [problem](/draft-5/getting-started/basic-concepts#problem) by returning the [`#problem`](/draft-5/commonerror/properties/problem) property of a specified object.

{% code title="common-error.class.ts" %}

```typescript
public get problem(): string {
  return this.#problem;
}
```

{% endcode %}

### Return type

#### [<mark style="color:green;">`string`</mark>](https://www.typescriptlang.org/docs/handbook/basic-types.html#string)

### Returns

The **return value** is the [problem](/draft-5/getting-started/basic-concepts#problem) of a [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) type.

## Example usage

```typescript
// Example usage.
import { CommonError } from '@angular-package/error';

// Extend the `CommonError` class.
class TestError<Id extends string> extends CommonError<Id> {}

// Returns "Problem accessor."
new TestError('Problem accessor.', 'Fix accessor.', '(AE:427)').problem;
```


# get template()

The get accessor gets the template of the error message

## `CommonError.prototype.template`

The [`get`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/get) accessor gets the [template](/draft-5/getting-started/basic-concepts#template) of the error message by returning the [`#template`](/draft-5/commonerror/properties/template) property of a specified object.

{% code title="common-error.class.ts" %}

```typescript
public get template(): string {
  return this.#template;
}
```

{% endcode %}

### Return type

#### [<mark style="color:green;">`string`</mark>](https://www.typescriptlang.org/docs/handbook/basic-types.html#string)

### Returns

The **return value** is the [template](/draft-5/getting-started/basic-concepts#template) of a [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) type.

## Example usage

```typescript
// Example usage.
import { CommonError } from '@angular-package/error';

// Extend the `CommonError` class.
class TestError<Id extends string> extends CommonError<Id> {}

// Returns "{problem} {fix} {id}".
new TestError(
  'Problem accessor.',
  'Fix accessor.',
  '(AE:427)',
  '{problem} {fix} {id}'
).template;
```


# Properties

The \`CommonError\` object properties

|                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| <p><strong>public static</strong> <a href="/pages/akE6vknq8khSYhbok2vb"><strong>template</strong></a><strong>:</strong> <mark style="color:green;">string</mark><br>A template of the error message of <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String"><code>string</code></a> type with the replaceable <a href="/pages/BbVb9Mj2Y9veAqrtKz61#problem"><code>{problem}</code></a>, <a href="/pages/BbVb9Mj2Y9veAqrtKz61#fix"><code>{fix}</code></a> and optional <a href="/pages/BbVb9Mj2Y9veAqrtKz61#id"><code>{id}</code></a>, <code>{link}</code>, <a href="/pages/BbVb9Mj2Y9veAqrtKz61#max"><code>{max}</code></a>, <a href="/pages/BbVb9Mj2Y9veAqrtKz61#min"><code>{min}</code></a>, <a href="/pages/BbVb9Mj2Y9veAqrtKz61#type"><code>{type}</code></a> tags.</p>                                                                                       |
| <p><a href="/pages/bM02xNqvdJvIfZJuzFc6"><strong>#fix</strong></a><strong>:</strong> <mark style="color:green;">string</mark><br>A privately stored possible solution to the described <a href="/pages/6Nle1uMltWSb2uh6hgTQ#problem">problem</a> of a <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String"><code>string</code></a> type</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| <p><a href="/pages/sM1pw7PS84C8cmqys4wZ"><strong>#id?</strong></a><strong>:</strong> <mark style="color:green;">Id</mark><br>Optional privately stored unique <a href="/pages/6Nle1uMltWSb2uh6hgTQ#identification">identification</a> of the described <a href="/pages/6Nle1uMltWSb2uh6hgTQ#problem">problem</a> of generic type variable <a href="/pages/PY4nixy9omXSectfeNl5#commonerror-less-than-id-greater-than"><code>Id</code></a>.</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| <p><a href="/pages/T7CzWe5vgWUYvAmOLUPa"><strong>#link?</strong></a><strong>:</strong> <mark style="color:green;">string</mark><br>The optional privately stored link of <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String"><code>string</code></a> type redirects to read more about the thrown error.</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| <p><a href="/pages/ni1YTHvL07t1jeocuGux"><strong>#problem</strong></a><strong>:</strong> <mark style="color:green;">string</mark><br>A privately stored <a href="/pages/6Nle1uMltWSb2uh6hgTQ#problem">problem</a> of a <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String"><code>string</code></a> type.</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| <p><a href="/pages/VT4SwlV0NwAnpvm5q6hg"><strong>#template</strong></a><strong>:</strong> <mark style="color:green;">string</mark><br>A <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string-type</a> privately stored <a href="/pages/6Nle1uMltWSb2uh6hgTQ#template">template</a> of the error <a href="/pages/6Nle1uMltWSb2uh6hgTQ#message">message</a> that contains replaceable required <a href="/pages/BbVb9Mj2Y9veAqrtKz61#fix"><code>{fix}</code></a>, <a href="/pages/BbVb9Mj2Y9veAqrtKz61#problem"><code>{problem}</code></a> and optional <a href="/pages/BbVb9Mj2Y9veAqrtKz61#id"><code>{id}</code></a>, <code>{link}</code>, <a href="/pages/BbVb9Mj2Y9veAqrtKz61#max"><code>{max}</code></a>, <a href="/pages/BbVb9Mj2Y9veAqrtKz61#min"><code>{min}</code></a>, <a href="/pages/BbVb9Mj2Y9veAqrtKz61#type"><code>{type}</code></a> tags.</p> |


# static template

A template of the error message of string type with the replaceable tags

## `CommonError.template`

A template of the error message of [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) type with the replaceable [`{problem}`](/draft-5/commonerror/constructor#problem), [`{fix}`](/draft-5/commonerror/constructor#fix) and optional [`{id}`](#id), [`{link}`](#link), [`{max}`](#max), [`{min}`](#min), [`{type}`](#type) tags.

{% hint style="info" %}
By default, it's set to:

`Problem{id}: {problem} => Fix: {fix}`.
{% endhint %}

{% code title="common-error.class.ts" %}

```typescript
public static template = `Problem{id}: {problem} => Fix: {fix}`;
```

{% endcode %}

### Tags

Replaceable tags on the [`template`](#template-string-commonerror.template).

#### `{fix}`

Replaceable by the given required [`fix`](/draft-5/commonerror/constructor#fix-string) parameter.

#### `{id}`

Replaceable by the given [`id`](/draft-5/commonerror/constructor#id-id) parameter.

#### `{link}`

Replaceable by the property `link` of the given [`additional`](/draft-5/commonerror/constructor#additional-min-number-max-number-type-string) parameter.

#### `{max}`

Replaceable by the property `max` of the given [`additional`](/draft-5/commonerror/constructor#additional-min-number-max-number-type-string) parameter.

#### `{min}`

Replaceable by the property `min` of the given [`additional`](/draft-5/commonerror/constructor#additional-min-number-max-number-type-string) parameter.

#### `{problem}`

Replaceable by the given required [`problem`](/draft-5/commonerror/constructor#problem-string) parameter.

#### `{type}`

Replaceable by the property `type` of the given [`additional`](/draft-5/commonerror/constructor#additional-min-number-max-number-type-string) parameter.

## Example usage

```typescript
// Example usage.
import { CommonError } from '@angular-package/error';

// Change the template.
CommonError.template = `Problem({id}): {problem} => Fix: {fix}`;

// Extend the `CommonError` class.
class TestError<Id extends string> extends CommonError<Id> {}

// Returns
// Error: Problem(AE:427): The `age` parameter is wrong. => Fix: Provided `age`
// must be different type.
new TestError(
  'The `age` parameter is wrong.', // Problem
  'Provided `age` must be different type. ', // Fix
  'AE:427' // Identification
);
```


# #fix

A privately stored possible solution to the described problem

## `#fix`

A privately stored possible [solution](/draft-5/getting-started/basic-concepts#fix) to the described [problem](/draft-5/getting-started/basic-concepts#problem) of a [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) type.

{% code title="common-error.class.ts" %}

```typescript
#fix: string;
```

{% endcode %}

### Type

#### [<mark style="color:green;">`string`</mark>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)


# #id?

A privately stored unique identification of the described problem

## `#id?`

Optional privately stored unique [identification](/draft-5/getting-started/basic-concepts#identification) of the described [problem](/draft-5/getting-started/basic-concepts#problem) of generic type variable [`Id`](/draft-5/commonerror/generic-type-variables#commonerror-less-than-id-greater-than).

{% code title="common-error.class.ts" %}

```typescript
#id?: Id;
```

{% endcode %}

### Type

#### [<mark style="color:green;">`Id`</mark>](/draft-5/commonerror/generic-type-variables#wrap-opening)


# #link?

The optional privately stored link redirects to read more about the thrown error

## `#link?`

The optional privately stored link of [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) type redirects to read more about the thrown error.

{% code title="common-error.class.ts" %}

```typescript
#link?: string;
```

{% endcode %}

### Type

#### [<mark style="color:green;">`string`</mark>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)


# #problem

A privately stored problem

## `#problem`

A privately stored [problem](/draft-5/getting-started/basic-concepts#problem) of a [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) type.

{% code title="common-error.class.ts" %}

```typescript
#problem: string;
```

{% endcode %}

### Type

#### [<mark style="color:green;">`string`</mark>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)


# #template

A string-type privately stored template of the error message that contains replaceable required \`{fix}\`, \`{problem}\` and optional \`{id}\`, \`{link}\`, \`{max}\`, \`{min}\`, \`{type}\` tags

## `#template`

A [string-type](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) privately stored [template](/draft-5/getting-started/basic-concepts#template) of the error [message](/draft-5/getting-started/basic-concepts#message) that contains replaceable required [`{fix}`](/draft-5/commonerror/constructor#fix), [`{problem}`](/draft-5/commonerror/constructor#problem) and optional [`{id}`](/draft-5/commonerror/constructor#id), `{link}`, [`{max}`](/draft-5/commonerror/constructor#max), [`{min}`](/draft-5/commonerror/constructor#min), [`{type}`](/draft-5/commonerror/constructor#type) tags.

{% code title="common-error.class.ts" %}

```typescript
#template: string;
```

{% endcode %}

### Type

#### [<mark style="color:green;">`string`</mark>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)


# Methods

The \`CommonError\` object methods

|                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| <p><strong>protected static</strong> <a href="/pages/KhI7uCqLCibWKkF1fp1b"><strong>defineMessage()</strong></a><strong>:</strong> <mark style="color:green;">string</mark><br>The static "<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals">tag</a>" method builds from the given <a href="/pages/KhI7uCqLCibWKkF1fp1b#...values-any"><code>values</code></a> the error message of a <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String"><code>string</code></a> type on the template.</p> |
| <p><strong>protected static</strong> <a href="/pages/EVnsL3y0PxCd21o8K9N0"><strong>isError()</strong></a><strong>:</strong> value is <mark style="color:green;">CommonError</mark><<mark style="color:green;">Id</mark>><br>Checks whether the <a href="/pages/EVnsL3y0PxCd21o8K9N0#value-any"><code>value</code></a> of any type is a <code>this</code> instance of any or the given <a href="/pages/EVnsL3y0PxCd21o8K9N0#id-id">identification</a>.</p>                                                                                                                            |


# static defineMessage()

The static "tag" method builds from the given values the error message

## `CommonError.defineMessage()`

The static "[tag](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals)" method builds from the given [`values`](#...values-any) the error message of a [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) type on the template.

{% code title="common-error.class.ts" %}

```typescript
protected static defineMessage(
  templateStringsArray: TemplateStringsArray,
  ...values: any[]
): string {
  let problem: string,
    fix: string,
    id: string | undefined,
    template: string,
    additional: { link?: string; min?: number; max?: number; type?: string };
  [problem, fix, id, template, additional] = values;
  template = (template || CommonError.template)
    .replace('{problem}', problem || '')
    .replace(/{id}/g, id || '')
    .replace(/{link}/g, additional?.link ? additional.link : '')
    .replace(/{max}/g, additional?.max ? String(additional.max) : '')
    .replace(/{min}/g, additional?.min ? String(additional.min) : '')
    .replace(/{type}/g, additional?.type ? additional.type : '')
    .replace('{fix}', fix || '');
  return template;
}
```

{% endcode %}

### Parameters

#### `templateStringsArray:`<mark style="color:green;">`TemplateStringsArray`</mark>

\-

#### `...values:`[<mark style="color:green;">`any`</mark>](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#any)`[]`

A rest parameter of expressions in order [`${problem}`](/draft-5/commonerror/constructor#problem-string), [`${fix}`](/draft-5/commonerror/constructor#fix-string), [`${id}`](/draft-5/commonerror/constructor#id-id), [`${template}`](https://error.angular-package.dev/draft-5/commonerror/methods/pages/BbVb9Mj2Y9veAqrtKz61#template-string-commonerror.template) and [`${additional}`](/draft-5/commonerror/constructor#additional-link-string-min-number-max-number-type-string).

### Returns

The re**turn value** is the error message of a [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) type created from the expressions given in the [`values`](#...values-any).

## Example usage

```typescript
// Example usage.
import { CommonError } from '@angular-package/error';

const problem = 'The given `age` parameter must be';
const fix = 'Provided string type is not accepted, change to ';
const id = 'AE: 427';
const template = `Issue({id}): {problem} of {type} between range {min} and {max}. {fix}{type}`;
const additional = { max: 27, min: 9, type: 'number' };

class TestError<Id extends string> extends CommonError<Id> {
  public static isError<Id extends string>(
    value: any,
    id?: Id
  ): value is CommonError<Id> {
    return super.isError(value, id);
  }

  public static defineMessage(
    templateStringsArray: TemplateStringsArray,
    ...values: any[]
  ): string {
    return super.defineMessage(templateStringsArray, ...values);
  }
}

// Returns
// Issue(AE: 427): The given `age` parameter must be of number between range 9 and 27. Provided string type is not accepted, change to number
TestError.defineMessage`${problem}${fix}${id}${template}${additional}`;
```


# static isError()

Checks whether the value of any type is a this instance of any or the given identification

## `CommonError.isError()`

Checks whether the [`value`](#value-any) of [`any`](https://www.typescriptlang.org/docs/handbook/basic-types.html#any) type is a `this` instance of any or the given [identification](#id-id).

{% code title="common-error.class.ts" %}

```typescript
protected static isError<Id extends string>(
  value: any,
  id?: Id
): value is CommonError<Id> {
  return typeof value === 'object' && value instanceof this
    ? typeof id === 'string'
      ? value.id === id
      : true
    : false;
}
```

{% endcode %}

### Generic type variables

#### <mark style="color:green;">`Id`</mark>`extends`[<mark style="color:green;">`string`</mark>](https://www.typescriptlang.org/docs/handbook/basic-types.html#string)

A generic type variable constrained by the [`string`](https://www.typescriptlang.org/docs/handbook/basic-types.html#string) indicates the&#x20;

### Parameters

#### `value:`[<mark style="color:green;">`any`</mark>](https://www.typescriptlang.org/docs/handbook/basic-types.html#any)

The value of [`any`](https://www.typescriptlang.org/docs/handbook/basic-types.html#any) type to check against the `this` instance.

#### `id?:`[<mark style="color:green;">`Id`</mark>](#idextendsstring)

Optional identification of generic type variable [`Id`](#idextendsstring) to check whether the given [`value`](#value-any) contains.

### Return type

#### `value is`[<mark style="color:green;">`CommonError`</mark>](/draft-5/commonerror/overview)`<`[<mark style="color:green;">`Id`</mark>](/draft-5/commonerror/generic-type-variables#commonerror-less-than-id-greater-than)`>`

The **return type** is a [`boolean`](https://www.typescriptlang.org/docs/handbook/basic-types.html#boolean) indicating the [`value`](#value-any) is the [`CommonError`](/draft-5/commonerror/overview) object that takes generic type variable [`Id`](/draft-5/commonerror/generic-type-variables#commonerror-less-than-id-greater-than).

### Returns

The **return value** is a [`boolean`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean) type indicating whether the given [`value`](#value-any) is a `this` instance of any or the given [`id`](#id-id).

## Example usage

```typescript
// Example usage.
import { CommonError } from '@angular-package/error';

class TestError<Id extends string> extends CommonError<Id> {
  public static isError<Id extends string>(
    value: any,
    id?: Id
  ): value is TestError<Id> {
    return super.isError(value, id);
  }
}

const testError = new TestError(
  'Problem accessor.',
  'Fix accessor.',
  '(AE:427)',
  '{problem} {fix} {id}'
);

// Returns "true".
TestError.isError(testError, '(AE:427)');
```


# Overview

The \`CommonErrors\` object

## `CommonErrors {}`

The `CommonErrors` object represents the storage of errors with [unique identification](/draft-5/getting-started/basic-concepts#unique-identification) numbers.

{% embed url="<https://github.com/angular-package/error/blob/main/src/lib/common-errors.class.ts>" %}
`common-errors.class.ts`
{% endembed %}

### **Accessors**

|                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| <p><strong>protected get</strong> <a href="/pages/17m0fDb46LZWkooB1FqX"><strong>errors()</strong></a><strong>:</strong> <mark style="color:green;">Map</mark><<mark style="color:green;">Id</mark>, <mark style="color:green;">any</mark>><br>The <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/get"><code>get</code></a> accessor returns the errors of <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map"><code>Map</code></a> type by returning the <a href="/pages/2ir7K33VMKRDy2vjKyP7"><code>#errors</code></a> property of a specified object.</p> |

### Properties

|                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| <p><strong>public static</strong> <a href="/pages/dOsyXdOuhEgblyUQ9QW5"><strong>template?</strong></a><strong>:</strong> <mark style="color:green;">string</mark></p><p>Optional template of <a href="https://www.typescriptlang.org/docs/handbook/basic-types.html#string"><code>string</code></a> type.</p>                                                                                                                                                                                                                     |
| <p><a href="/pages/JAuIoagdUhqE3FJbZEcf"><strong>#id?</strong></a><strong>:</strong> <mark style="color:green;">Set</mark><<mark style="color:green;">Id</mark>><br>The collection of unique allowed <a href="/pages/6Nle1uMltWSb2uh6hgTQ#unique-identification">identification</a> numbers of generic type variable <a href="/pages/fKW6bm1HGWKrX5c1MDO3#commonerrors-less-than-id-greater-than"><code>Id</code></a>.</p>                                                                                                        |
| <p><a href="/pages/2ir7K33VMKRDy2vjKyP7"><strong>#errors</strong></a><strong>:</strong> <mark style="color:green;">Map</mark><<mark style="color:green;">Id</mark>, <mark style="color:green;">any</mark>><br>The errors storage of the <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map"><code>Map</code></a> type where the <code>key</code> is of the generic type variable <a href="/pages/fKW6bm1HGWKrX5c1MDO3#commonerrors-less-than-id-greater-than"><code>Id</code></a>.</p> |

### Methods

|                                                                                                                                                                                                                                                                                                                                                                                                                             |
| --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| <p><strong>public</strong> <a href="/pages/xi0YKoG8xZkgZN9NkFaw"><strong>delete()</strong></a><strong>:</strong> <mark style="color:green;">this</mark></p><p>Deletes the error of a specified <a href="/pages/xi0YKoG8xZkgZN9NkFaw#id-errorid"><code>id</code></a> from the object.</p>                                                                                                                                    |
| <p><strong>public</strong> <a href="/pages/5dVyxHbYOjpt7OCBaNam"><strong>has()</strong></a><strong>:</strong> <mark style="color:green;">boolean</mark><br>The <code>has()</code> method checks whether the error of the given <a href="/pages/5dVyxHbYOjpt7OCBaNam#id-errorid"><code>id</code></a> exists in a specified object.</p>                                                                                       |
| <p><strong>public</strong> <a href="/pages/T7Dy5DRfviVlHi4BXeuA"><strong>throw()</strong></a><strong>:</strong> <mark style="color:green;">void</mark><br>Throws an error of the given <a href="/pages/T7Dy5DRfviVlHi4BXeuA#id-errorid"><code>id</code></a> if the unique <a href="/pages/mb13waFtHVZxVvkUgUwQ#...id-id"><code>id</code></a> was provided in the <a href="/pages/mb13waFtHVZxVvkUgUwQ">constructor</a>.</p> |
| <p><strong>protected</strong> <a href="/pages/PkOMsn22h7BbWBQydoO7"><strong>isAllowedId()</strong></a><strong>:</strong> <mark style="color:green;">boolean</mark><br>Checks whether the given <a href="/pages/6Nle1uMltWSb2uh6hgTQ#unique-identification">identification</a> number was provided in the <a href="/pages/mb13waFtHVZxVvkUgUwQ">constructor</a>.</p>                                                         |


# Generic type variables

The \`CommonErrors\` generic type variables

## `CommonErrors<`<mark style="color:green;background-color:green;">`Id`</mark>`>`

#### <mark style="color:green;">`Id`</mark>`extends`[<mark style="color:green;">`string`</mark>](https://www.typescriptlang.org/docs/handbook/basic-types.html#string)

​A generic type variable constrained by the [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String), by default of the value **captured** from the provided rest parameter [`id`](https://error.angular-package.dev/draft-5/commonerrors/pages/mb13waFtHVZxVvkUgUwQ#...id-id) indicates the identification type of a new [`CommonErrors`](/draft-5/commonerrors/overview) instance.

{% code title="common-errors.class.ts" %}

```typescript
abstract class CommonErrors<
  Id extends string // <--- Declare generic type variable Id.
> {
  constructor(
    ...id: Id[] // <--- Capture generic type variable Id.
  ) {
    Array.isArray(id) && (this.#id = new Set(id));
  }
}
```

{% endcode %}


# Constructor

The \`CommonErrors\` constructor

## `CommonErrors()`

Creates an instance of the errors storage with [unique identification](/draft-5/getting-started/basic-concepts#unique-identification) numbers.

{% hint style="info" %}
Identification numbers given in the rest parameter [`id`](#...id-id) are used by the instance [`isAllowedId()`](/draft-5/commonerrors/methods/isallowedid) method to check the existence of the specific [`id`](#...id-id).
{% endhint %}

{% code title="common-errors.class.ts" %}

```typescript
constructor(...id: Id[]) {
  Array.isArray(id) && (this.#id = new Set(id));
}
```

{% endcode %}

### Parameters

#### `...id:`[<mark style="color:green;">`Id`</mark>](/draft-5/commonerrors/generic-type-variables#commonerrors-less-than-id-greater-than)`[]`

A [rest parameter](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/rest_parameters) of generic type variable [`Id`](/draft-5/commonerrors/generic-type-variables#commonerrors-less-than-id-greater-than) indicates [unique identification](/draft-5/getting-started/basic-concepts#unique-identification) numbers under which the errors are stored in the object.

## Example usage

```typescript
// 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');
```


# Accessors

The \`CommonErrors\` accessors

|                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| <p><strong>protected get</strong> <a href="/pages/17m0fDb46LZWkooB1FqX"><strong>errors()</strong></a><strong>:</strong> <mark style="color:green;">Map</mark><<mark style="color:green;">Id</mark>, <mark style="color:green;">any</mark>><br>The <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/get"><code>get</code></a> accessor returns the errors of <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map"><code>Map</code></a> type by returning the <a href="/pages/2ir7K33VMKRDy2vjKyP7"><code>#errors</code></a> property of a specified object.</p> |


# get errors()

The get accessor returns the errors of Map type

## `CommonErrors.prototype.errors()`

The [`get`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/get) accessor returns the errors of [`Map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map) type by returning the [`#errors`](/draft-5/commonerrors/properties/errors) property of a specified object.

{% code title="common-errors.class.ts" %}

```typescript
protected get errors(): Map<Id, any> {
  return this.#errors;
}
```

{% endcode %}

### Return type

#### `Map<`[<mark style="color:green;">`Id`</mark>](/draft-5/commonerrors/generic-type-variables#commonerrors-less-than-id-greater-than)`,`[<mark style="color:green;">`any`</mark>](https://www.typescriptlang.org/docs/handbook/basic-types.html#any)`>`

### Returns

The **return value** is the [`Map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map) object of errors.


# Properties

The \`CommonErrors\` properties

|                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| <p><strong>public static</strong> <a href="/pages/dOsyXdOuhEgblyUQ9QW5"><strong>template?</strong></a><strong>:</strong> <mark style="color:green;">string</mark><br>Optional template of <a href="https://www.typescriptlang.org/docs/handbook/basic-types.html#string"><code>string</code></a> type.</p>                                                                                                                                                                                                                                                                     |
| <p><a href="/pages/JAuIoagdUhqE3FJbZEcf"><strong>#id?</strong></a><strong>:</strong> <mark style="color:green;">Set</mark><<a href="/pages/fKW6bm1HGWKrX5c1MDO3#wrap-opening"><mark style="color:green;">Id</mark></a>></p><p>An optional collection of unique allowed <a href="/pages/6Nle1uMltWSb2uh6hgTQ#unique-identification">identification</a> numbers of generic type variable <a href="/pages/fKW6bm1HGWKrX5c1MDO3#commonerrors-less-than-id-greater-than"><code>Id</code></a> under which errors are stored.</p>                                                     |
| <p><a href="/pages/2ir7K33VMKRDy2vjKyP7"><strong>#errors</strong></a><strong>:</strong> <mark style="color:green;">Map</mark><<a href="/pages/fKW6bm1HGWKrX5c1MDO3"><mark style="color:green;">Id</mark></a>, <mark style="color:green;">any</mark>></p><p>The errors storage of the <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map"><code>Map</code></a> type where the <code>key</code> is of the generic type variable <a href="/pages/fKW6bm1HGWKrX5c1MDO3#commonerrors-less-than-id-greater-than"><code>Id</code></a>.</p> |


# static template?

Optional template

## `CommonErrors.template`

Optional template of [`string`](https://www.typescriptlang.org/docs/handbook/basic-types.html#string) type.

{% code title="common-errors.class.ts" %}

```typescript
public static template?: string;
```

{% endcode %}

### Type

#### [<mark style="color:green;">`string`</mark>](https://www.typescriptlang.org/docs/handbook/basic-types.html#string)


# #id?

The collection of unique allowed identification numbers

## `#id?`

An optional collection of unique allowed [identification](/draft-5/getting-started/basic-concepts#unique-identification) numbers of generic type variable [`Id`](/draft-5/commonerrors/generic-type-variables#commonerrors-less-than-id-greater-than) under which errors are stored.

{% code title="common-errors.class.ts" %}

```typescript
#id?: Set<Id>;
```

{% endcode %}

### Type

#### `Set<`[<mark style="color:green;">`Id`</mark>](/draft-5/commonerrors/generic-type-variables#commonerrors-less-than-id-greater-than)`>`


# #errors

The errors storage of the Map type

## `#errors`

The errors storage of the [`Map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map) type where the `key` is of the generic type variable [`Id`](/draft-5/commonerrors/generic-type-variables#commonerrors-less-than-id-greater-than).

{% code title="common-errors.class.ts" %}

```typescript
#errors: Map<Id, any> = new Map();
```

{% endcode %}

### Type

#### `Map<`[<mark style="color:green;">`Id`</mark>](/draft-5/commonerrors/generic-type-variables#commonerrors-less-than-id-greater-than)`,`[<mark style="color:green;">`any`</mark>](https://www.typescriptlang.org/docs/handbook/basic-types.html#any)`>`


# Methods

The \`CommonErrors\` methods

|                                                                                                                                                                                                                                                                                                                                                                                                                             |
| --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| <p><strong>public</strong> <a href="/pages/xi0YKoG8xZkgZN9NkFaw"><strong>delete()</strong></a><strong>:</strong> <mark style="color:green;">this</mark><br>Deletes the error of a specified <a href="/pages/xi0YKoG8xZkgZN9NkFaw#id-errorid"><code>id</code></a> from the object.</p>                                                                                                                                       |
| <p><strong>public</strong> <a href="/pages/5dVyxHbYOjpt7OCBaNam"><strong>has()</strong></a><strong>:</strong> <mark style="color:green;">boolean</mark><br>The <code>has()</code> method checks whether the error of the given <a href="/pages/5dVyxHbYOjpt7OCBaNam#id-errorid"><code>id</code></a> exists in a specified object.</p>                                                                                       |
| <p><strong>public</strong> <a href="/pages/T7Dy5DRfviVlHi4BXeuA"><strong>throw()</strong></a><strong>:</strong> <mark style="color:green;">void</mark><br>Throws an error of the given <a href="/pages/T7Dy5DRfviVlHi4BXeuA#id-errorid"><code>id</code></a> if the unique <a href="/pages/mb13waFtHVZxVvkUgUwQ#...id-id"><code>id</code></a> was provided in the <a href="/pages/mb13waFtHVZxVvkUgUwQ">constructor</a>.</p> |
| <p><strong>protected</strong> <a href="/pages/PkOMsn22h7BbWBQydoO7"><strong>isAllowedId()</strong></a><strong>:</strong> <mark style="color:green;">boolean</mark><br>Checks whether the given <a href="/pages/6Nle1uMltWSb2uh6hgTQ#unique-identification">identification</a> number was provided in the <a href="/pages/mb13waFtHVZxVvkUgUwQ">constructor</a>.</p>                                                         |


# delete()

Deletes the error of a specified id from the object

## `CommonErrors.prototype.delete()`

Deletes the error of a specified [`id`](#id-errorid) from the object.&#x20;

{% code title="common-errors.class.ts" %}

```typescript
public delete<ErrorId extends Id>(id: ErrorId): this {
  this.#errors.delete(id);
  return this;
}
```

{% endcode %}

### Generic type variables

#### <mark style="color:green;">`ErrorId`</mark>`extends`[<mark style="color:green;">`Id`</mark>](/draft-5/commonerrors/generic-type-variables#wrap-opening)

A generic type variable `ErrorId` constrained by the generic type variable [`Id`](/draft-5/commonerrors/generic-type-variables#commonerrors-less-than-id-greater-than) of the [`CommonErrors`](/draft-5/commonerrors/overview) object indicates the type picked from the [`Id`](/draft-5/commonerrors/generic-type-variables#commonerrors-less-than-id-greater-than) and its exact type is useful in picking the specific error from the storage.

### Parameters

#### `id:`[<mark style="color:green;">`ErrorId`</mark>](#erroridextendsid)

The unique identification of a generic type variable [`ErrorId`](#erroridextendsid) to remove the error from the object.

### Return type

#### <mark style="color:green;">`this`</mark>

## Example usage

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

// Define new `TestClass` to add error to the map storage.
export class TestClass<Id extends string> extends CommonErrors<Id> {
  public get errors(): Map<Id, any> {
    return super.errors;
  }
  public set<ErrorId extends Id>(
    problem: string,
    fix: string,
    id: ErrorId
  ): this {
    this.errors.set(id, new Error(problem, fix, id));
    return this;
  }
}

// Initialize the `TestClass`.
const generalErrors = new TestClass('EG: 4332', 'EG: 4331', 'EG: 4330');

// Set the errors.
generalErrors
  .set(
    'Bad parameter type, detected number',
    'Provide proper type, the `string`',
    'EG: 4330'
  )
  .set('Detected numbers', 'Provide only letters', 'EG: 4331');

// Returns Map(2)
generalErrors.errors;

// Deletes the error of the `EG: 4330` identification number.
generalErrors.delete('EG: 4330');

// Returns Map(1)
generalErrors.errors;
```


# has()

Checks whether the error of the given id exists in a specified object

## `CommonErrors.prototype.has()`

The `has()` method checks whether the error of the given [`id`](#id-errorid) exists in a specified object.

{% code title="common-errors.class.ts" %}

```typescript
public has<ErrorId extends Id>(id: ErrorId): boolean {
  return this.#errors.has(id);
}
```

{% endcode %}

### Generic type variables

#### <mark style="color:green;">`ErrorId`</mark>`extends`[<mark style="color:green;">`Id`</mark>](/draft-5/commonerrors/generic-type-variables#wrap-opening)

A generic type variable `ErrorId` constrained by the generic type variable [`Id`](/draft-5/commonerrors/generic-type-variables#commonerrors-less-than-id-greater-than) of the [`CommonErrors`](/draft-5/commonerrors/overview) object indicates the type picked from the [`Id`](/draft-5/commonerrors/generic-type-variables#commonerrors-less-than-id-greater-than) and its exact type is useful in picking the specific error from the storage.

### Parameters

#### `id:`[<mark style="color:green;">`ErrorId`</mark>](#erroridextendsid)

The error identification number of generic type variable [`ErrorId`](#erroridextendsid) to test for the presence of the error in the object.

### Return type

#### <mark style="color:green;">`this`</mark>

## Example usage

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

// Define new `TestClass` to add error to the map storage.
export class TestClass<Id extends string> extends CommonErrors<Id> {
  public get errors(): Map<Id, any> {
    return super.errors;
  }
  public set<ErrorId extends Id>(
    problem: string,
    fix: string,
    id: ErrorId
  ): this {
    this.errors.set(id, new Error(problem, fix, id));
    return this;
  }
}

// Initialize the `TestClass`.
const generalErrors = new TestClass('EG: 4332', 'EG: 4331', 'EG: 4330');

// Set the errors.
generalErrors
  .set(
    'Bad parameter type, detected number',
    'Provide proper type, the `string`',
    'EG: 4330'
  )
  .set('Detected numbers', 'Provide only letters', 'EG: 4331');

// Returns `true`.
generalErrors.has('EG: 4330');

// Returns `false`.
generalErrors.has('EG: 4332');
```


# throw()

Throws an error of the given identification

## `CommonErrors.prototype.throw()`

Throws an error of the given [`id`](#id-errorid) if the unique id was provided in the [constructor](/draft-5/commonerrors/constructor).

{% code title="common-errors.class.ts" %}

```typescript
public throw<ErrorId extends Id>(id: ErrorId): void {
  if (this.isAllowedId(id)) {
    throw this.errors.get(id);
  }
}
```

{% endcode %}

### Generic type variables

#### <mark style="color:green;">`ErrorId`</mark>`extends`[<mark style="color:green;">`Id`</mark>](/draft-5/commonerrors/generic-type-variables#commonerrors-less-than-id-greater-than)

A generic type variable `ErrorId` constrained by the generic type variable [`Id`](/draft-5/commonerrors/generic-type-variables#commonerrors-less-than-id-greater-than) of the [`CommonErrors`](/draft-5/commonerrors/overview) object indicates the type picked from the [`Id`](/draft-5/commonerrors/generic-type-variables#commonerrors-less-than-id-greater-than) and its exact type is useful in picking the specific error from the storage.

### Parameters

#### `id:`[<mark style="color:green;">`ErrorId`</mark>](#erroridextendsid)

The unique identification of a generic type variable [`ErrorId`](#erroridextendsid) to remove the error from the object.

### Return type

#### <mark style="color:green;">`this`</mark>

## Example usage

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

// Define new `TestClass` to add error to the map storage.
export class TestClass<Id extends string> extends CommonErrors<Id> {
  public get errors(): Map<Id, any> {
    return super.errors;
  }
  public set<ErrorId extends Id>(
    problem: string,
    fix: string,
    id: ErrorId
  ): this {
    this.errors.set(id, new Error(problem, fix, id));
    return this;
  }
}

// Initialize the `TestClass`.
const generalErrors = new TestClass('EG: 4332', 'EG: 4331', 'EG: 4330');

// Set the errors.
generalErrors
  .set(
    'Bad parameter type, detected number',
    'Provide proper type, the `string`',
    'EG: 4330'
  )
  .set(
    'Detected numbers',
    'Provide only letters',
    'EG: 4331'
  );


try {
  // Throw the specified EG: 4330 error.
  generalErrors.throw('EG: 4330');
} catch (e) {
  if (e instanceof Error) {
    e.fix; // Provide proper type, the `string`
    e.message; // ProblemEG: 4330: Bad parameter type, detected number => Fix: Provide proper type, the `string`
    e.name; // Error
    e.problem; // Bad parameter type, detected number
    e.template; // Problem{id}: {problem} => Fix: {fix}
    e.id; // EG: 4330
  }
}
```


# isAllowedId()

Checks whether the given identification number was provided in the constructor

## `CommonErrors.prototype.isAllowedId()`

Checks whether the given [identification](/draft-5/getting-started/basic-concepts#unique-identification) number was provided in the [constructor](/draft-5/commonerrors/constructor).

{% code title="common-errors.class.ts" %}

```typescript
protected isAllowedId<ErrorId extends Id>(id: ErrorId): boolean {
  return this.#id ? this.#id.has(id) : false;
}
```

{% endcode %}

### Generic type variables

#### <mark style="color:green;">`ErrorId`</mark>`extends`[<mark style="color:green;">`Id`</mark>](/draft-5/commonerrors/generic-type-variables#commonerrors-less-than-id-greater-than)

A generic type variable `ErrorId` constrained by the generic type variable [`Id`](/draft-5/commonerrors/generic-type-variables#commonerrors-less-than-id-greater-than) of the [`CommonErrors`](/draft-5/commonerrors/overview) object indicates the type picked from the [`Id`](/draft-5/commonerrors/generic-type-variables#commonerrors-less-than-id-greater-than) and its exact type is useful in picking the specific error from the storage.

### Parameters

#### `id:`[<mark style="color:green;">`ErrorId`</mark>](#erroridextendsid)

The error identification number of generic type variable [`ErrorId`](#erroridextendsid) to test for its presence in the object.

### Return type

#### <mark style="color:green;">`this`</mark>

## Example usage

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

// Define new `TestClass` to add error to the map storage.
export class TestClass<Id extends string> extends CommonErrors<Id> {
  public get errors(): Map<Id, any> {
    return super.errors;
  }
  public set<ErrorId extends Id>(
    problem: string,
    fix: string,
    id: ErrorId
  ): this {
    // <--- Use the isAllowedId() here ----------------
    if (super.isAllowedId(id)) {
      this.errors.set(id, new Error(problem, fix, id));
    }
    // <-----------------------------------------------
    return this;
  }
}

// Initialize the `TestClass`.
const generalErrors = new TestClass('EG: 4332', 'EG: 4331', 'EG: 4330');

// Set the errors.
generalErrors
  .set(
    'Bad parameter type, detected number',
    'Provide proper type, the `string`',
    'EG: 3000' as any // <--- Wrong ID
  )
  .set(
    'Detected numbers',
    'Provide only letters',
    'EG: 4335' as any // <--- Wrong ID
  );

// Returns Map(0) {size: 0}
generalErrors.errors;

  // Returns `false`.
generalErrors.has('EG: 3000' as any);

// Returns `false`.
generalErrors.has('EG: 4335' as any);
```


# Overview

The \`Error\` object

## `Error {}`

The `Error` object is an extension of the [`CommonError`](/draft-5/commonerror/overview) class and is thrown when a runtime error occurs with a [message](https://app.gitbook.com/s/23iV8ygEQUrhqw7I3D8g/~/changes/lXvTfsmAkHoNRKsQjxlq/commonerror/accessors/get-message) built from a [solution](https://app.gitbook.com/s/23iV8ygEQUrhqw7I3D8g/~/changes/lXvTfsmAkHoNRKsQjxlq/commonerror/accessors/get-fix) to the described [problem](https://app.gitbook.com/s/23iV8ygEQUrhqw7I3D8g/~/changes/lXvTfsmAkHoNRKsQjxlq/commonerror/accessors/get-problem) but with additional identification, on the [template](https://app.gitbook.com/s/23iV8ygEQUrhqw7I3D8g/~/changes/lXvTfsmAkHoNRKsQjxlq/commonerror/accessors/get-template).

{% embed url="<https://github.com/angular-package/error/blob/main/src/lib/error.class.ts>" %}
`error.class.ts`
{% endembed %}

### Accessors

|                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| <p><strong>public get</strong> <a href="/pages/GXdNT2b4zHCktwMOBCO9"><strong>name()</strong></a><strong>:</strong> <mark style="color:green;">string</mark><br>Error name of a <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String"><code>string</code></a> type, set to <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error"><code>Error</code></a> that is being thrown.</p>                                                                                                                                                                                                                                                         |
| <p><strong>public get</strong> <a href="/pages/3RgFr3AxYItRzky1Z8Kj"><strong>[Symbol.</strong><mark style="color:blue;"><strong>toStringTag</strong></mark><strong>](https://error.angular-package.dev/draft-5/error)</strong></a><strong>:</strong> <mark style="color:green;">string</mark><br>The <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/get"><code>get</code></a> accessor, with the help of <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toStringTag"><code>toStringTag</code></a>, changes the default tag to <code>'Error'</code> for an instance of <a href="/pages/8orEKqBluVa8xEGaGvh8"><code>Error</code></a>.</p> |

### Properties

|                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| <p><strong>public static</strong> <a href="/pages/akE6vknq8khSYhbok2vb"><strong>template</strong></a><strong>:</strong> <mark style="color:green;">string</mark><br>A template of the error message of <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String"><code>string</code></a> type with the replaceable <a href="/pages/BbVb9Mj2Y9veAqrtKz61#problem"><code>{problem}</code></a>, <a href="/pages/BbVb9Mj2Y9veAqrtKz61#fix"><code>{fix}</code></a> and optional <a href="/pages/BbVb9Mj2Y9veAqrtKz61#id"><code>{id}</code></a> tags.</p> |

### Methods

|                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| <p><strong>public static</strong> <a href="/pages/mUNe2R3Rnn68BZeJX7Hz"><strong>define()</strong></a><strong>:</strong> <mark style="color:green;">Error</mark><<mark style="color:green;">Id</mark>><br>Defines the <a href="#error"><code>Error</code></a> instance with the <a href="/pages/UAsNmVmOuYGxNypELFFh">message</a> built of the given required <a href="/pages/mUNe2R3Rnn68BZeJX7Hz#problem-string"><code>problem</code></a>, <a href="/pages/mUNe2R3Rnn68BZeJX7Hz#fix-string"><code>fix</code></a> and optional <a href="/pages/mUNe2R3Rnn68BZeJX7Hz#id-id"><code>id</code></a> on the <a href="/pages/mUNe2R3Rnn68BZeJX7Hz#template-error.template"><code>template</code></a>.</p> |
| <p><strong>public static</strong> <a href="/pages/Yk0fHW48jbBFpZjZoUkS"><strong>isError()</strong></a><strong>:</strong> value is <mark style="color:green;">Error</mark><<mark style="color:green;">Id</mark>><br>Checks whether the <a href="#value-any"><code>value</code></a> of <a href="https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#any"><code>any</code></a> type is an instance of <a href="/pages/8orEKqBluVa8xEGaGvh8"><code>Error</code></a> of any or the given <a href="#id-id">identification</a>.</p>                                                                                                                                                        |


# Generic type variables

The \`Error\` object generic type variables

## `Error<`<mark style="color:green;background-color:green;">`Id`</mark>`>`

#### <mark style="color:green;">`Id`</mark>`extends`[<mark style="color:green;">`string`</mark>](https://www.typescriptlang.org/docs/handbook/basic-types.html#string)

​A generic type variable constrained by the [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String), by default of the value **captured** from the provided [`id`](/draft-5/error/constructor#id-id) indicates the [identification](/draft-5/getting-started/basic-concepts#identification) type of a new [`Error`](/draft-5/error/overview) instance.

{% code title="error.class.ts" %}

```typescript
class Error<
  Id extends string  // <--- Declare generic type variable Id.
> extends CommonError<Id> {
  ...
  constructor(
    problem: string,
    fix: string,
    id?: Id,  // <--- Capture generic type variable Id.
    template = Error.template
  ) { ... }
  ...
}
```

{% endcode %}


# ★ Constructor

The \`Error\` object constructor

## `Error()`

Creates the [`Error`](/draft-5/error/overview) instance with the [message](/draft-5/commonerror/accessors/get-message) built from the given described [`problem`](#problem-string) and its [solution](#fix-string), optional explicit [identification](#id-id) on the given or stored [`template`](#template-string-error.template).

{% code title="error.class.ts" %}

```typescript
constructor(
  problem: string,
  fix: string,
  id?: Id,
  template = Error.template
) {
  super(problem, fix, id, template);
}
```

{% endcode %}

### Parameters

#### `problem:`[<mark style="color:green;">`string`</mark>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)

Description of the [problem](/draft-5/getting-started/basic-concepts#problem) of a [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) type.

#### `fix:`[<mark style="color:green;">`string`</mark>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)

A solution to the given [`problem`](#problem-string) of a [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) type.

#### `id?:`[<mark style="color:green;">`Id`</mark>](/draft-5/error/generic-type-variables#wrap-opening)

Optional unique [identification](/draft-5/getting-started/basic-concepts#identification) to the given [`problem`](#problem-string) of generic type variable [`Id`](/draft-5/commonerror/generic-type-variables#commonerror-less-than-id-greater-than).

#### `template:`[<mark style="color:green;">`string`</mark>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)`=`<mark style="color:green;">`Error`</mark>`.template`

A template of error message with the replaceable [`{problem}`](/draft-5/commonerror/properties/static-template#problem), [`{fix}`](/draft-5/commonerror/properties/static-template#fix) and optional [`{id}`](/draft-5/commonerror/properties/static-template#id) tags. By default, the value is equal to the static property [`template`](/draft-5/commonerror/properties/static-template).

## Example usage

```typescript
// Example usage.
import { Error } from '@angular-package/error';

// Returns "Error: ProblemTE:201: Wrong type => Fix: Change the type".
new Error('Wrong type', 'Change the type', 'TE:201');
```


# Accessors

The \`Error\` object accessors.

|                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| <p><strong>public get</strong> <a href="/pages/GXdNT2b4zHCktwMOBCO9"><strong>name()</strong></a><strong>:</strong> <mark style="color:green;">string</mark><br>Error name of a <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String"><code>string</code></a> type, set to <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error"><code>'Error'</code></a> that is being thrown.</p>                                                                                                                                                                                                                                                       |
| <p><strong>public get</strong> <a href="/pages/3RgFr3AxYItRzky1Z8Kj"><strong>[Symbol.</strong><mark style="color:blue;"><strong>toStringTag</strong></mark><strong>](https://error.angular-package.dev/draft-5/error)</strong></a><strong>:</strong> <mark style="color:green;">string</mark><br>The <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/get"><code>get</code></a> accessor, with the help of <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toStringTag"><code>toStringTag</code></a>, changes the default tag to <code>'Error'</code> for an instance of <a href="/pages/8orEKqBluVa8xEGaGvh8"><code>Error</code></a>.</p> |


# get name()

The \`get\` accessor obtains error object name

## `Error.prototype.name`

Error name of a [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) type, set to [`'Error'`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error) that is being thrown.

{% code title="error.class.ts" %}

```typescript
public get name(): string {
  return 'Error';
}
```

{% endcode %}

### Return type

#### [<mark style="color:green;">`string`</mark>](https://www.typescriptlang.org/docs/handbook/basic-types.html#string)

### Returns

The **return value** is the error instance name of [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) type.&#x20;

## Example usage

```typescript
// Example usage.
import { Error } from '@angular-package/error';

// Returns "Error".
new Error('Wrong type', 'Change the type', 'TE:201').name;
```


# get \[Symbol.toStringTag]\()

Changes the default tag to 'RangeError' for an instance

## `[Symbol.toStringTag]()`

The [`get`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/get) accessor, with the help of [`toStringTag`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toStringTag), changes the default tag to `'Error'` for an instance of [`Error`](/draft-5/error/overview). It can be read by the [`typeOf()`](https://docs.angular-package.dev/v/type/helper/typeof) function of [`@angular-package/type`](https://docs.angular-package.dev/v/type/).

{% code title="error.class.ts" %}

```typescript
public get [Symbol.toStringTag](): string {
  return 'Error';
}
```

{% endcode %}

### Return type

#### [<mark style="color:green;">`string`</mark>](https://www.typescriptlang.org/docs/handbook/basic-types.html#string)

### Returns

The **return value** is the word `Error` of a [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String).

## Example usage

```typescript
// Example usage.
import { Error } from '@angular-package/error';
import { typeOf } from '@angular-package/type';

// Returns "error".
typeOf(new Error('problem', 'fix solution'));
```


# Methods

The \`Error\` object methods

|                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| <p><strong>public static</strong> <a href="/pages/mUNe2R3Rnn68BZeJX7Hz"><strong>define()</strong></a><strong>:</strong> <mark style="color:green;">Error</mark><<mark style="color:green;">Id</mark>><br>Defines the <a href="/pages/8orEKqBluVa8xEGaGvh8"><code>Error</code></a> instance with the <a href="/pages/UAsNmVmOuYGxNypELFFh">message</a> built of the given required <a href="/pages/mUNe2R3Rnn68BZeJX7Hz#problem-string"><code>problem</code></a>, <a href="/pages/mUNe2R3Rnn68BZeJX7Hz#fix-string"><code>fix</code></a> and optional <a href="/pages/mUNe2R3Rnn68BZeJX7Hz#id-id"><code>id</code></a> on the <a href="/pages/mUNe2R3Rnn68BZeJX7Hz#template-error.template"><code>template</code></a>.</p> |
| <p><strong>public static</strong> <a href="/pages/Yk0fHW48jbBFpZjZoUkS"><strong>isError()</strong></a><strong>:</strong> value is <mark style="color:green;">Error</mark><<mark style="color:green;">Id</mark>><br>Checks whether the <a href="#value-any"><code>value</code></a> of <a href="https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#any"><code>any</code></a> type is an instance of <a href="/pages/8orEKqBluVa8xEGaGvh8"><code>Error</code></a> of any or the given <a href="#id-id">identification</a>.</p>                                                                                                                                                                             |


# static define()

Defines the \`Error\` instance.

## `Error.define()`

Defines the [`Error`](/draft-5/error/overview) instance with the [message](/draft-5/commonerror/accessors/get-message) built of the given required [`problem`](#problem-string), [`fix`](#fix-string) and optional [`id`](#id-id) on the given or stored [`template`](#template-error.template).

{% code title="error.class.ts" %}

```typescript
public static define<Id extends string>(
  problem: string,
  fix: string,
  id?: Id,
  template = Error.template
): Error<Id> {
  return new this(problem, fix, id, template);
}
```

{% endcode %}

### Generic type variables

#### <mark style="color:green;">`Id`</mark>`extends`[<mark style="color:green;">`string`</mark>](https://www.typescriptlang.org/docs/handbook/basic-types.html#string)

A generic type variable constrained by the [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String), by default of the value **captured** from the provided optional [`id`](#id-id) indicates the [identification](/draft-5/getting-started/basic-concepts#identification) type of a new [`Error`](/draft-5/error/overview) instance.

### Parameters

#### `problem:`[<mark style="color:green;">`string`</mark>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)

Description of the [problem](/draft-5/getting-started/basic-concepts#problem) of a [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) type.

#### `fix:`[<mark style="color:green;">`string`</mark>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)

A solution to the given [`problem`](#problem-string) of a [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) type.

#### `id?:`[<mark style="color:green;">`Id`</mark>](#idextendsstring)

Optional unique [identification](/draft-5/getting-started/basic-concepts#identification) to the given [`problem`](#problem-string) of generic type variable [`Id`](#idextendsstring).

#### `template =`<mark style="color:green;">`Error`</mark>`.template`

A template of error message with the replaceable [`{problem}`](/draft-5/commonerror/properties/static-template#problem), [`{fix}`](/draft-5/commonerror/properties/static-template#fix) and optional [`{id}`](/draft-5/commonerror/properties/static-template#id) tags. By default, the value is equal to the static property [`template`](/draft-5/commonerror/properties/static-template).

### Return type

#### `Error<`[<mark style="color:green;">`Id`</mark>](#idextendsstring)`>`

The **return type** is the [`Error`](/draft-5/error/overview) object that takes generic type variable [`Id`](#idextendsstring).

### Returns

The **return value** is a new instance of the [`Error`](/draft-5/error/overview) with the [message](/draft-5/commonerror/accessors/get-message) built from the given required [`problem`](#problem-string), [`fix`](#fix-string) and optional [`id`](#id-id) on the [`template`](#template-error.template).

## Example usage

```typescript
// Example usage.
import { Error } from '@angular-package/error';

// Returns "Error: ProblemTE:201: Wrong type => Fix: Change the type".
Error.define('Wrong type', 'Change the type', 'TE:201');
```


# static isError()

Checks whether the value of any type is an instance of \`Error\`.

## `Error.isError()`

Checks whether the [`value`](#value-any) of [`any`](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#any) type is an instance of [`Error`](/draft-5/error/overview) of any or the given [identification](#id-id).

{% code title="error.class.ts" %}

```typescript
public static isError<Id extends string>(
  value: any,
  id?: Id
): value is Error<Id> {
  return super.isError(value, id);
}
```

{% endcode %}

### Generic type variables

#### <mark style="color:green;">`Id`</mark>`extends`[<mark style="color:green;">`string`</mark>](https://www.typescriptlang.org/docs/handbook/basic-types.html#string)

A generic type variable constrained by the [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String), by default of the value **captured** from the provided optional [`id`](#id-id) indicates the [identification](/draft-5/getting-started/basic-concepts#identification) type of the [`Error`](/draft-5/error/overview) via [return type](#return-type).

### Parameters

#### `value:`[<mark style="color:green;">`any`</mark>](https://www.typescriptlang.org/docs/handbook/basic-types.html#any)

The value of [`any`](https://www.typescriptlang.org/docs/handbook/basic-types.html#any) type to check against the [`Error`](/draft-5/error/overview) instance.

#### `id?:`[<mark style="color:green;">`Id`</mark>](#idextendsstring)

Optional unique [identification](/draft-5/getting-started/basic-concepts#identification) of generic type variable [`Id`](#idextendsstring) that the given [`value`](#value-any) contains.

### Return type

#### `value is Error<`[<mark style="color:green;">`Id`</mark>](#idextendsstring)`>`

The **return type** is a [`boolean`](https://www.typescriptlang.org/docs/handbook/basic-types.html#boolean) resulting from its statement indicating the [`value`](#value-any) is the [`Error`](/draft-5/error/overview) object that takes the generic type variable [`Id`](#idextendsstring).

### Returns

The **return value** is a [`boolean`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean) type indicating whether the given [`value`](#value-any) is an instance of [`Error`](/draft-5/error/overview) of any or the given [`id`](#id-id).

## Example usage

```typescript
// Example usage.
import { Error } from '@angular-package/error';

// Define error.
const err = Error.define('Wrong type', 'Change the type', 'TE:201');

// Returns true.
Error.isError(err);

// Returns true.
Error.isError(err, 'TE:201');

// Returns false.
Error.isError(err, 'TE:202');

// Returns false.
Error.isError(new Array());
```


# Overview

The \`Errors\` object

## `Errors {}`

The `Errors` is an extension of the [`CommonErrors`](/draft-5/commonerrors/overview) object that represents multiple identification numbers under which the errors of the [`Error`](/draft-5/error/overview) type are prepared to throw.

{% embed url="<https://github.com/angular-package/error/blob/main/src/lib/errors.class.ts>" %}
`errors.class.ts`
{% endembed %}

### Methods

|                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |                                                                                                                                                                                                                                                                                                                                                                                                 |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| <p><strong>public</strong> <a href="/pages/qrXPIluGyuNOjRJclTQY"><strong>get()</strong></a><strong>:</strong> <mark style="color:green;">Error</mark><<mark style="color:green;">ErrorId</mark>>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         | <mark style="color:green;">undefined</mark><br>Returns the <a href="/pages/8orEKqBluVa8xEGaGvh8"><code>Error</code></a> instance of the given unique identification <a href="/pages/qrXPIluGyuNOjRJclTQY#id-errorid"><code>id</code></a> if set, otherwise <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined"><code>undefined</code></a>.</p> |
| <p><strong>public</strong> <a href="/pages/AeDEXpmMWQXeXhFssnyv"><strong>getErrors()</strong></a><strong>:</strong> { \[<mark style="color:green;">Key</mark> in <mark style="color:green;">Id</mark>]: <mark style="color:green;">Error</mark><<mark style="color:green;">Key</mark>> }<br>Returns an <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object"><code>object</code></a> of set errors, where the key is a <a href="/pages/6Nle1uMltWSb2uh6hgTQ#unique-identification">unique identification</a>.</p>                                                                                                                                                            |                                                                                                                                                                                                                                                                                                                                                                                                 |
| <p><strong>public</strong> <a href="/pages/g8g9UoxtaZpiUPOeeRPP"><strong>set()</strong></a><strong>:</strong> <mark style="color:green;">this</mark><br>Sets the <a href="/pages/8orEKqBluVa8xEGaGvh8"><code>Error</code></a> object with the message built from the given required <a href="/pages/g8g9UoxtaZpiUPOeeRPP#problem-string"><code>problem</code></a>, <a href="/pages/g8g9UoxtaZpiUPOeeRPP#id-errorid"><code>id</code></a>, <a href="/pages/g8g9UoxtaZpiUPOeeRPP#fix-string"><code>fix</code></a> on the given or stored <a href="/pages/g8g9UoxtaZpiUPOeeRPP#template-errors.template"><code>template</code></a> under the given <a href="/pages/g8g9UoxtaZpiUPOeeRPP#id-errorid"><code>id</code></a>.</p> |                                                                                                                                                                                                                                                                                                                                                                                                 |


# Generic type variables

The \`Errors\` generic type variables

## `Errors<`<mark style="color:green;background-color:green;">`Id`</mark>`>`

#### <mark style="color:green;">`Id`</mark>`extends`[<mark style="color:green;">`string`</mark>](https://www.typescriptlang.org/docs/handbook/basic-types.html#string)

​A generic type variable constrained by the [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String), by default of the value **captured** from the provided rest parameter [`id`](https://error.angular-package.dev/draft-5/errors/pages/Rzj09cNrHTtgm07LoS3R#...id-id) indicates the identification type of a new [`Errors`](/draft-5/errors/overview) instance.

{% code title="errors.class.ts" %}

```typescript
class Errors<
  Id extends string // <--- Declare generic type variable Id.
> extends CommonErrors<Id> {
  constructor(
    ...id: Id[] // <--- Capture generic type variable Id.
  ) {
    super(...id);
  }
}
```

{% endcode %}


# Constructor

Creates the \`Errors\` instance of unique identification numbers under which the \`Error\` objects are stored

## `Errors()`

Creates the [`Errors`](/draft-5/errors/overview) instance of [unique identification](/draft-5/getting-started/basic-concepts#unique-identification) numbers under which the [`Error`](/draft-5/error/overview) objects are stored.

{% code title="errors.class.ts" %}

```typescript
constructor(...id: Id[]) {
  super(...id);
}
```

{% endcode %}

### Parameters

#### `...id:`[<mark style="color:green;">`Id`</mark>](/draft-5/errors/generic-type-variables#errors-less-than-id-greater-than)`[]`

A [rest parameter](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/rest_parameters) of generic type variable [`Id`](/draft-5/errors/generic-type-variables#errors-less-than-id-greater-than) indicates [unique identification](/draft-5/getting-started/basic-concepts#unique-identification) numbers under which the errors are stored in the object.

## Example usage

```typescript
// Example usage.
import { Errors } from '@angular-package/error';

// Returns Errors {}
new Errors('EG: 4332', 'EG: 4331', 'EG: 4330');
```


# Methods

The \`Errors\` object methods

|                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |                                                                                                                                                                                                                                                                                                                                                                                                 |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| <p><strong>public</strong> <a href="/pages/qrXPIluGyuNOjRJclTQY"><strong>get()</strong></a><strong>:</strong> <mark style="color:green;">Error</mark><<mark style="color:green;">ErrorId</mark>>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         | <mark style="color:green;">undefined</mark><br>Returns the <a href="/pages/8orEKqBluVa8xEGaGvh8"><code>Error</code></a> instance of the given unique identification <a href="/pages/qrXPIluGyuNOjRJclTQY#id-errorid"><code>id</code></a> if set, otherwise <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined"><code>undefined</code></a>.</p> |
| <p><strong>public</strong> <a href="/pages/AeDEXpmMWQXeXhFssnyv"><strong>getErrors()</strong></a><strong>:</strong> { \[<mark style="color:green;">Key</mark> in <mark style="color:green;">Id</mark>]: <mark style="color:green;">Error</mark><<mark style="color:green;">Key</mark>> }<br>Returns an <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object"><code>object</code></a> of set errors, where the key is a <a href="/pages/6Nle1uMltWSb2uh6hgTQ#unique-identification">unique identification</a>.</p>                                                                                                                                                            |                                                                                                                                                                                                                                                                                                                                                                                                 |
| <p><strong>public</strong> <a href="/pages/g8g9UoxtaZpiUPOeeRPP"><strong>set()</strong></a><strong>:</strong> <mark style="color:green;">this</mark><br>Sets the <a href="/pages/8orEKqBluVa8xEGaGvh8"><code>Error</code></a> object with the message built from the given required <a href="/pages/g8g9UoxtaZpiUPOeeRPP#problem-string"><code>problem</code></a>, <a href="/pages/g8g9UoxtaZpiUPOeeRPP#id-errorid"><code>id</code></a>, <a href="/pages/g8g9UoxtaZpiUPOeeRPP#fix-string"><code>fix</code></a> on the given or stored <a href="/pages/g8g9UoxtaZpiUPOeeRPP#template-errors.template"><code>template</code></a> under the given <a href="/pages/g8g9UoxtaZpiUPOeeRPP#id-errorid"><code>id</code></a>.</p> |                                                                                                                                                                                                                                                                                                                                                                                                 |


# get()

Returns the \`Error\` instance of the given unique identification

## `Errors.prototype.get()`

Returns the [`Error`](/draft-5/error/overview) instance of the given unique identification [`id`](#id-errorid) if set, otherwise [`undefined`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined).

{% code title="errors.class.ts" %}

```typescript
public get<ErrorId extends Id>(id: ErrorId): Error<ErrorId> | undefined {
  return this.errors.get(id);
}
```

{% endcode %}

### Generic type variables

#### <mark style="color:green;">`ErrorId`</mark>`extends`[<mark style="color:green;">`Id`</mark>](/draft-5/errors/generic-type-variables#errors-less-than-id-greater-than)

A generic type variable `ErrorId` constrained by the generic type variable [`Id`](/draft-5/errors/generic-type-variables#errors-less-than-id-greater-than) of the [`Errors`](/draft-5/errors/overview) object indicates the type picked from the [`Id`](/draft-5/errors/generic-type-variables#errors-less-than-id-greater-than) and its exact type is useful in picking the specific error from the storage.

### Parameters

#### `id:`[<mark style="color:green;">`ErrorId`</mark>](#erroridextendsid)

The [unique identification](/draft-5/getting-started/basic-concepts#unique-identification) number of generic type variable [`ErrorId`](#erroridextendsid) to pick an error from the object.

### Return type

#### `Error<`[<mark style="color:green;">`ErrorId`</mark>](#erroridextendsid)`> |`[<mark style="color:green;">`undefined`</mark>](https://www.typescriptlang.org/docs/handbook/basic-types.html#null-and-undefined)

The **return type** is the [`Error`](/draft-5/error/overview) object that takes the generic type variable [`ErrorId`](#erroridextendsid) or [`undefined`](https://www.typescriptlang.org/docs/handbook/basic-types.html#null-and-undefined).

### Returns

The **return value** is the [`Error`](/draft-5/typeerror/overview) instance of the given [`id`](#id-errorid) if set, otherwise [`undefined`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined).

## Example usage

```typescript
// Example usage.
import { Errors } from '@angular-package/error';

// Define general errors.
const generalErrors = new Errors('EG: 4332', 'EG: 4331', 'EG: 4330');

// Set the `Error` objects under the given identification numbers.
generalErrors
  .set(
    'Bad parameter type, detected number',
    'Provide proper type, the `string`',
    'EG: 4330'
  )
  .set('Detected numbers', 'Provide only letters', 'EG: 4331');

// Returns the Error<"EG: 4330">.
generalErrors.get('EG: 4330');
```


# getErrors()

The method returns the object of set errors

## `Errors.prototype.getErrors()`

Returns an [`object`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object) of set errors, where the key is a [unique identification](/draft-5/getting-started/basic-concepts#unique-identification).

{% code title="errors.class.ts" %}

```typescript
public getErrors(): { [Key in Id]: Error<Key> | undefined } {
  return Object.fromEntries(this.errors.entries()) as any;
}
```

{% endcode %}

### Return type

#### `{ [`<mark style="color:green;">`Key`</mark>`in`[<mark style="color:green;">`Id`</mark>](/draft-5/errors/generic-type-variables#errors-less-than-id-greater-than)`]: Error<`<mark style="color:green;">`Key`</mark>`> |`<mark style="color:green;">`undefined`</mark>` ``}`

A **return type** is an object of the [`Error`](/draft-5/error/overview) objects or [`undefined`](https://www.typescriptlang.org/docs/handbook/basic-types.html#null-and-undefined) in the keys of generic type variable [`Id`](/draft-5/errors/generic-type-variables#errors-less-than-id-greater-than).

### Returns

The **return value** is an [`object`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object) of set errors.

## Example usage

```typescript
// Example usage.
import { Errors } from '@angular-package/error';

// Define general errors.
const generalErrors = new Errors('EG: 4332', 'EG: 4331', 'EG: 4330');

// Set the `Error` objects under the given identification numbers.
generalErrors
  .set(
    'Bad parameter type, detected number',
    'Provide proper type, the `string`',
    'EG: 4330'
  )
  .set('Detected numbers', 'Provide only letters', 'EG: 4331');

// Returns:
/*
Returns
  {
    EG: 4330: ...,
    EG: 4331: ...
  }
  of type
  {
    "EG: 4332": Error<"EG: 4332">;
    "EG: 4331": Error<"EG: 4331">;
    "EG: 4330": Error<"EG: 4330">;
  }
*/
generalErrors.getErrors();
```


# set()

Sets the \`Error\` object under the given \`id\`

## `Errors.prototype.set()`

Sets the [`Error`](/draft-5/error/overview) object with the message built from the given required [`problem`](#problem-string), [`fix`](#fix-string), [`id`](#id-errorid) on the given or stored [`template`](#template-errors.template) under the given [`id`](#id-errorid).

{% code title="errors.class.ts" %}

```typescript
public set<ErrorId extends Id>(
  problem: string,
  fix: string,
  id: ErrorId,
  template = Errors.template
): this {
  this.isAllowedId(id) &&
    this.errors.set(id, new Error(problem, fix, id, template));
  return this;
}
```

{% endcode %}

### Generic type variables

#### <mark style="color:green;">`ErrorId`</mark>`extends`[<mark style="color:green;">`Id`</mark>](/draft-5/errors/generic-type-variables#errors-less-than-id-greater-than)

A generic type variable `ErrorId` constrained by the generic type variable [`Id`](/draft-5/errors/generic-type-variables#errors-less-than-id-greater-than) of the [`Errors`](/draft-5/errors/overview) object indicates the type picked from the [`Id`](/draft-5/errors/generic-type-variables#errors-less-than-id-greater-than) and its exact type is useful in picking the specific error from the storage.

### Parameters

#### `problem:`[<mark style="color:green;">`string`</mark>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)

Description of the problem of a [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) type.

#### `fix:`[<mark style="color:green;">`string`</mark>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)

A solution to the given [`problem`](#problem-string) of a [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) type.

#### `id:`[<mark style="color:green;">`ErrorId`</mark>](#erroridextendsid)

The unique identification to the given [`problem`](#problem-string) of generic type variable [`ErrorId`](#erroridextendsid).

#### `template =`[<mark style="color:green;">`Errors`</mark>](/draft-5/errors/overview)`.template`

A template of error message with the replaceable [`{problem}`](/draft-5/commonerror/properties/static-template#problem), [`{fix}`](/draft-5/commonerror/properties/static-template#fix), [`{id}`](/draft-5/commonerror/properties/static-template#id) tags. By default, the value is equal to the static property `Errors.template`.

### Return type

#### <mark style="color:green;">`this`</mark>

## Example usage

```typescript
// Example usage.
import { Errors } from '@angular-package/error';

// Define general errors.
const generalErrors = new Errors('EG: 4332', 'EG: 4331', 'EG: 4330');

// Set the `Error` objects under the given identification numbers.
generalErrors
  .set(
    'Bad parameter type, detected number',
    'Provide proper type, the `string`',
    'EG: 4330'
  )
  .set('Detected numbers', 'Provide only letters', 'EG: 4331');
```


# Example usage

The \`Errors\` object example usage

```typescript
// Example usage.
import { Errors } from '@angular-package/error';

// Define general errors.
const generalErrors = new Errors('(GE:021)', '(GE:022)', '(GE:027)');
```

### `set()`

```typescript
// Set the `Error` objects under the given identification numbers.
generalErrors
  .set('Bad parameter', 'Provide the `install` parameter', '(GE:021)')
  .set('Bad function', 'Provide the function', '(GE:022)')
  .set('Wrong title', 'Provide only letters', '(GE:027)');
```

### `delete()`

```typescript
// Example `delete()` method usage.
generalErrors.delete('(GE:022)');
```

### `get()`

```typescript
// Example `get()` usage.

// Returns `undefined`.
generalErrors.get('(GE:022)');

// Returns Error: Problem(GE:027): Wrong title => Fix: Provide only letters
generalErrors.get('(GE:027)'); 
```

### `has()`

```typescript
// Example `has()` usage.

// Returns `false`.
generalErrors.has('(GE:022)');

// Returns `true`.
generalErrors.has('(GE:027)'); 
```

### `throw()`

```typescript
// Example `throw()` usage.

// Uncaught Error: Problem(GE:027): Wrong title => Fix: Provide only letters
generalErrors.has('(GE:027)'); 
```


# Overview

The \`RangeError\` object

## `RangeError {}`

The `RangeError` object is an extension of the [`CommonError`](/draft-5/commonerror/overview) class and is thrown when a value is not in the set or range of allowed values with the message built from the described problem and its solution, optional explicit identification and minimum/maximum range on the given or stored template.

{% embed url="<https://github.com/angular-package/error/blob/main/src/lib/range-error.class.ts>" %}
`range-error.class.ts`
{% endembed %}

### Accessors

|                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| <p><strong>public get</strong> <a href="/pages/NxbK0CCmXotwf62SPRSv"><strong>max()</strong></a><strong>:</strong> <mark style="color:green;">Max</mark>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        | <mark style="color:green;">undefined</mark><br>The <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/get"><code>get</code></a> accessor obtains the maximum range of generic type variable <a href="/pages/4o4mE7ENn7hKzuk12xAY#rangeerror-less-than-id-min-max-greater-than-2"><code>Max</code></a> that causes an error to be thrown(or not thrown), if set, otherwise returns <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined"><code>undefined</code></a>.</p> |
| <p><strong>public get</strong> <a href="/pages/hAUnk7kQWfBzQorubNcw"><strong>min()</strong></a><strong>:</strong> <mark style="color:green;">Min</mark>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        | <mark style="color:green;">undefined</mark><br>The <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/get"><code>get</code></a> accessor obtains the minimum range of generic type variable <a href="/pages/4o4mE7ENn7hKzuk12xAY#rangeerror-less-than-id-min-max-greater-than-1"><code>Min</code></a> that causes an error to be thrown(or not thrown), if set, otherwise returns <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined"><code>undefined</code></a>.</p> |
| <p><strong>public get</strong> <a href="/pages/w2qz76L9DB4zOc0HfiTs"><strong>name()</strong></a><strong>:</strong> <mark style="color:green;">string</mark> <br>Error name of a <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String"><code>string</code></a> type, set to <code>'RangeError'</code> that is being thrown.</p>                                                                                                                                                                                                                                                                                                                                                                     |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| <p><strong>public get</strong> <a href="/pages/hNpHiHHjvVmOjCfqZqYf"><strong>range()</strong></a><strong>:</strong> { min?: <mark style="color:green;">Min</mark>; max?: <mark style="color:green;">Max</mark> } <br>The <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/get"><code>get</code></a> accessor obtains the <a href="/pages/hAUnk7kQWfBzQorubNcw">minimum</a> and <a href="/pages/NxbK0CCmXotwf62SPRSv">maximum</a> range in the form of an <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object">object</a>.</p>                                                                                                                                 |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| <p><strong>public get</strong> <a href="/pages/UILbX43HX7GQA8UqJOmo"><strong>[Symbol.</strong><mark style="color:blue;"><strong>toStringTag</strong></mark><strong>](https://error.angular-package.dev/draft-5/rangeerror)</strong></a><strong>:</strong> <mark style="color:green;">string</mark><br>The <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/get"><code>get</code></a> accessor, with the help of <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toStringTag"><code>toStringTag</code></a>, changes the default tag to <code>'RangeError'</code> for an instance of <a href="/pages/XTL5Khe1PhScTJnRkiDh"><code>RangeError</code></a>.</p> |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |

### Properties

|                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| <p><strong>public static</strong> <a href="/pages/yqgr3HjFTyrXiV7yh0Xx"><strong>template</strong></a><strong>:</strong> <mark style="color:green;">string</mark><br>A template of the error message of <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String"><code>string</code></a> type with the replaceable <a href="/pages/akE6vknq8khSYhbok2vb#problem"><code>{problem}</code></a>, <a href="/pages/akE6vknq8khSYhbok2vb#fix"><code>{fix}</code></a> and optional <a href="/pages/akE6vknq8khSYhbok2vb#id"><code>{id}</code></a>, <a href="/pages/akE6vknq8khSYhbok2vb#max"><code>{max}</code></a>, <a href="/pages/akE6vknq8khSYhbok2vb#min"><code>{min}</code></a> tags.</p> |
| <p><a href="/pages/BuTFE6zoCgaGuhnnIVFt"><strong>#max?</strong></a><strong>:</strong> <mark style="color:green;">Max</mark><br>Private property of the <a href="/pages/6Nle1uMltWSb2uh6hgTQ#range">maximum range</a> of generic type variable <a href="/pages/4o4mE7ENn7hKzuk12xAY#rangeerror-less-than-id-min-max-greater-than-2"><code>Max</code></a> that causes an error to be thrown(or not thrown).</p>                                                                                                                                                                                                                                                                                                                   |
| <p><a href="/pages/I2ne0dK2qnw4AnG6ML2h"><strong>#min?</strong></a><strong>:</strong> <mark style="color:green;">Min</mark><br>Private property of the <a href="/pages/6Nle1uMltWSb2uh6hgTQ#range">minimum range</a> of generic type variable <a href="/pages/4o4mE7ENn7hKzuk12xAY#minextendsnumber-or-undefined-undefined"><code>Min</code></a> that causes an error to be thrown(or not thrown).</p>                                                                                                                                                                                                                                                                                                                          |

### Methods

|                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| <p><strong>public static</strong> <a href="/pages/pIRw6dz385L7OxhSnFpa"><strong>define()</strong></a><strong>:</strong> <mark style="color:green;">RangeError</mark><<mark style="color:green;">Id</mark>, <mark style="color:green;">Min</mark>, <mark style="color:green;">Max</mark>><br>Defines the <a href="/pages/XTL5Khe1PhScTJnRkiDh"><code>RangeError</code></a> instance with the <a href="/pages/UAsNmVmOuYGxNypELFFh">message</a> built from the given required <a href="/pages/pIRw6dz385L7OxhSnFpa#problem-string"><code>problem</code></a>, <a href="/pages/pIRw6dz385L7OxhSnFpa#fix-string"><code>fix</code></a> and optional <a href="/pages/pIRw6dz385L7OxhSnFpa#id-id"><code>id</code></a>, <a href="/pages/pIRw6dz385L7OxhSnFpa#max-max"><code>max</code></a>, <a href="/pages/pIRw6dz385L7OxhSnFpa#min-min"><code>min</code></a> on the given or stored <a href="/pages/pIRw6dz385L7OxhSnFpa#template-rangeerror.template"><code>template</code></a>.</p> |
| <p><strong>public static</strong> <a href="/pages/lUISc8abHJfLgsx2BRMZ"><strong>isRangeError()</strong></a><strong>:</strong> value is <mark style="color:green;">RangeError</mark><<mark style="color:green;">Id</mark>, <mark style="color:green;">Min</mark>, <mark style="color:green;">Max</mark>><br>Checks whether the <a href="/pages/lUISc8abHJfLgsx2BRMZ#value-any"><code>value</code></a> of <a href="https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#any"><code>any</code></a> type is an instance of <a href="/pages/XTL5Khe1PhScTJnRkiDh"><code>RangeError</code></a> of any or the given <a href="/pages/lUISc8abHJfLgsx2BRMZ#min-number">minimum</a>/<a href="/pages/lUISc8abHJfLgsx2BRMZ#max-number">maximum</a> range and <a href="/pages/lUISc8abHJfLgsx2BRMZ#id-id">identification</a>.</p>                                                                                                                                             |


# Generic type variables

The \`RangeError\` object generic type variables

## `RangeError<`<mark style="color:green;background-color:green;">`Id`</mark>`,Min,Max>`

#### <mark style="color:green;">`Id`</mark>`extends`[<mark style="color:green;">`string`</mark>](https://www.typescriptlang.org/docs/handbook/basic-types.html#string)

​A generic type variable constrained by the [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String), by default of the value **captured** from the provided [`id`](/draft-5/rangeerror/constructor#id-id) indicates the [identification](/draft-5/getting-started/basic-concepts#identification) type of a new [`RangeError`](/draft-5/rangeerror/overview) instance.

{% code title="range-error.class.ts" %}

```typescript
class RangeError<
  Id extends string, // <--- Declare generic type variable Id.
  Min extends number | undefined = undefined,
  Max extends number | undefined = undefined
> extends CommonError<Id> {
  ...
  constructor(
    problem: string,
    fix: string,
    id?: Id, // <--- Capture generic type variable Id.
    min?: Min,
    max?: Max,
    template = RangeError.template
  ) { ... }
  ...
}
```

{% endcode %}

## `RangeError<Id,`<mark style="color:green;background-color:green;">`Min`</mark>`,Max>`

#### <mark style="color:green;">`Min`</mark>`extends`[<mark style="color:green;">`number`</mark>](https://www.typescriptlang.org/docs/handbook/basic-types.html#number)`|`[<mark style="color:green;">`undefined`</mark>](https://www.typescriptlang.org/docs/handbook/basic-types.html#null-and-undefined)`=`[<mark style="color:green;">`undefined`</mark>](https://www.typescriptlang.org/docs/handbook/basic-types.html#null-and-undefined)

​A generic type variable constrained by the [`number`](https://www.typescriptlang.org/docs/handbook/basic-types.html#number) and [`undefined`](https://www.typescriptlang.org/docs/handbook/basic-types.html#null-and-undefined), by default of the value **captured** from the provided [`min`](/draft-5/rangeerror/constructor#min-min) indicates the minimum range type of a new [`RangeError`](/draft-5/rangeerror/overview) instance.

{% code title="range-error.class.ts" %}

```typescript
class RangeError<
  Id extends string,
  Min extends number | undefined = undefined, // <--- Declare generic type variable Min.
  Max extends number | undefined = undefined
> extends CommonError<Id> {
  ...
  constructor(
    problem: string,
    fix: string,
    id?: Id,
    min?: Min, // <--- Capture generic type variable Min.
    max?: Max,
    template = RangeError.template
  ) { ... }
  ...
}
```

{% endcode %}

## `RangeError<Id,Min,`<mark style="color:green;background-color:green;">`Max`</mark>`>`

#### <mark style="color:green;">`Max`</mark>`extends`[<mark style="color:green;">`number`</mark>](https://www.typescriptlang.org/docs/handbook/basic-types.html#number)`|`[<mark style="color:green;">`undefined`</mark>](https://www.typescriptlang.org/docs/handbook/basic-types.html#null-and-undefined)`=`[<mark style="color:green;">`undefined`</mark>](https://www.typescriptlang.org/docs/handbook/basic-types.html#null-and-undefined)

​A generic type variable constrained by the [`number`](https://www.typescriptlang.org/docs/handbook/basic-types.html#number) and [`undefined`](https://www.typescriptlang.org/docs/handbook/basic-types.html#null-and-undefined) by default of the value **captured** from the provided [`max`](/draft-5/rangeerror/constructor#max-max) indicates the maximum range type of a new [`RangeError`](/draft-5/rangeerror/overview) instance.

{% code title="range-error.class.ts" %}

```typescript
class RangeError<
  Id extends string,
  Min extends number | undefined = undefined,
  Max extends number | undefined = undefined // <--- Declare generic type variable Max.
> extends CommonError<Id> {
  ...
  constructor(
    problem: string,
    fix: string,
    id?: Id,
    min?: Min,
    max?: Max, // <--- Capture generic type variable Max.
    template = RangeError.template
  ) { ... }
  ...
}
```

{% endcode %}


# ★ Constructor

The \`RangeError\` object constructor

## `RangeError()`

Creates the [`RangeError`](/draft-5/rangeerror/overview) instance that represents range error with the [message](/draft-5/commonerror/accessors/get-message) built of the given described [`problem`](#problem-string) and its [solution](#fix-string), optional [`min`](#min-min)/[`max`](#max-max) range, and an explicit [identification](#id-id) on the given or stored error message [template](#template-string-rangerror.template).

{% code title="error.class.ts" %}

```typescript
constructor(
  problem: string,
  fix: string,
  id?: Id,
  min?: Min,
  max?: Max,
  template = RangeError.template
) {
  super(problem, fix, id, template, { min, max });
  this.#max = max;
  this.#min = min;
}
```

{% endcode %}

### Parameters

#### `problem:`[<mark style="color:green;">`string`</mark>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)

Description of the problem of a [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) type.

#### `fix:`[<mark style="color:green;">`string`</mark>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)

A solution to the given [`problem`](#problem-string) of a [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) type.

#### `id?:`[<mark style="color:green;">`Id`</mark>](/draft-5/rangeerror/generic-type-variables#rangeerror-less-than-id-min-max-greater-than)

Optional unique identification to the given [`problem`](#problem-string) of generic type variable [`Id`](/draft-5/rangeerror/generic-type-variables#rangeerror-less-than-id-min-max-greater-than).

#### `min?:`[<mark style="color:green;">`Min`</mark>](/draft-5/rangeerror/generic-type-variables#rangeerror-less-than-id-min-max-greater-than-1)

The optional minimum range of generic type variable [`Min`](/draft-5/rangeerror/generic-type-variables#rangeerror-less-than-id-min-max-greater-than-1) that causes an error to be thrown(or not thrown).

#### `max?:`[<mark style="color:green;">`Max`</mark>](/draft-5/rangeerror/generic-type-variables#rangeerror-less-than-id-min-max-greater-than-2)

The optional maximum range of generic type variable [`Max`](/draft-5/rangeerror/generic-type-variables#rangeerror-less-than-id-min-max-greater-than-2) that causes an error to be thrown(or not thrown).

#### `template:`[<mark style="color:green;">`string`</mark>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)`=`<mark style="color:green;">`RangError`</mark>`.template`

Optional template of the error message of [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) type with the replaceable [`{problem}`](/draft-5/commonerror/properties/static-template#problem), [`{fix}`](/draft-5/commonerror/properties/static-template#fix) and optional [`{id}`](/draft-5/commonerror/properties/static-template#id), [`{max}`](/draft-5/commonerror/properties/static-template#max), [`{min}`](/draft-5/commonerror/properties/static-template#min) tags. By default, the value is equal to the static property [`RangeError.template`](/draft-5/rangeerror/properties/static-template).

## Example usage

```typescript
// Example usage.
import { RangeError } from '@angular-package/error';

/*
  Returns
  RangeError: Problem(AE:427): The `age` parameter is too big, got 455 => Fix: Set the `age` parameter of the `setAge()` method between 9 and 27
*/
new RangeError(
  'The `age` parameter is too big, got 455', // Problem
  'Set the `age` parameter of the `setAge()` method', // Fix
  '(AE:427)', // Identification
  9,  // Minimum
  27 // Maximum range
);
```


# Accessors

The \`RangeError\` object accessors

|                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| <p><strong>public get</strong> <a href="/pages/NxbK0CCmXotwf62SPRSv"><strong>max()</strong></a><strong>:</strong> <mark style="color:green;">Max</mark>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       | <mark style="color:green;">undefined</mark><br>The <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/get"><code>get</code></a> accessor obtains the maximum range of generic type variable <a href="/pages/4o4mE7ENn7hKzuk12xAY#rangeerror-less-than-id-min-max-greater-than-2"><code>Max</code></a> that causes an error to be thrown(or not thrown), if set, otherwise returns <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined"><code>undefined</code></a>.</p> |
| <p><strong>public get</strong> <a href="/pages/hAUnk7kQWfBzQorubNcw"><strong>min()</strong></a><strong>:</strong> <mark style="color:green;">Min</mark>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       | <mark style="color:green;">undefined</mark><br>The <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/get"><code>get</code></a> accessor obtains the minimum range of generic type variable <a href="/pages/4o4mE7ENn7hKzuk12xAY#rangeerror-less-than-id-min-max-greater-than-1"><code>Min</code></a> that causes an error to be thrown(or not thrown), if set, otherwise returns <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined"><code>undefined</code></a>.</p> |
| <p><strong>public get</strong> <a href="/pages/w2qz76L9DB4zOc0HfiTs"><strong>name()</strong></a><strong>:</strong> <mark style="color:green;">string</mark> <br>Error name of a <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String"><code>string</code></a> type, set to <code>'RangeError'</code> that is being thrown.</p>                                                                                                                                                                                                                                                                                                                                                    |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| <p><strong>public get</strong> <a href="/pages/hNpHiHHjvVmOjCfqZqYf"><strong>range()</strong></a>: { min?: <mark style="color:green;">Min</mark>; max?: <mark style="color:green;">Max</mark> } <br>The <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/get"><code>get</code></a> accessor obtains the <a href="/pages/hAUnk7kQWfBzQorubNcw">minimum</a> and <a href="/pages/NxbK0CCmXotwf62SPRSv">maximum</a> range in the form of an <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object">object</a>.</p>                                                                                                                                 |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| <p><strong>public get</strong> <a href="/pages/UILbX43HX7GQA8UqJOmo"><strong>[Symbol.</strong><mark style="color:blue;"><strong>toStringTag</strong></mark><strong>](https://error.angular-package.dev/draft-5/rangeerror)</strong></a>: <mark style="color:green;">string</mark><br>The <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/get"><code>get</code></a> accessor, with the help of <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toStringTag"><code>toStringTag</code></a>, changes the default tag to <code>'RangeError'</code> for an instance of <a href="/pages/XTL5Khe1PhScTJnRkiDh"><code>RangeError</code></a>.</p> |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |


# get max()

The \`get\` accessor obtains the maximum range

## `RangeError.prototype.max`

The [`get`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/get) accessor obtains the maximum range of generic type variable [`Max`](/draft-5/rangeerror/generic-type-variables#rangeerror-less-than-id-min-max-greater-than-2) that causes an error to be thrown(or not thrown), if set, otherwise returns [`undefined`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined).

{% code title="range-error.class.ts" %}

```typescript
public get max(): Max | undefined {
  return this.#max;
}
```

{% endcode %}

### Return type

#### [<mark style="color:green;">`Max`</mark>](/draft-5/rangeerror/generic-type-variables#rangeerror-less-than-id-min-max-greater-than-2)`|`[<mark style="color:green;">`undefined`</mark>](https://www.typescriptlang.org/docs/handbook/basic-types.html#null-and-undefined)

### Returns

The **return value** is the maximum range of generic type variable [`Max`](/draft-5/rangeerror/generic-type-variables#rangeerror-less-than-id-min-max-greater-than-2) or [`undefined`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined).

## Example usage

```typescript
// Example usage.
import { RangeError } from '@angular-package/error';

// Returns "27".
new RangeError('problem', 'Fix accessor.', '(AE:427)', 9, 27).max;
```


# get min()

The \`get\` accessor obtains the minimum range

## `RangeError.prototype.min`

The [`get`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/get) accessor obtains the minimum range of generic type variable [`Min`](/draft-5/rangeerror/generic-type-variables#rangeerror-less-than-id-min-max-greater-than-1) that causes an error to be thrown(or not thrown), if set, otherwise returns [`undefined`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined).

{% code title="range-error.class.ts" %}

```typescript
public get min(): Min | undefined {
  return this.#min;
}
```

{% endcode %}

### Return type

#### [<mark style="color:green;">`Min`</mark>](/draft-5/rangeerror/generic-type-variables#rangeerror-less-than-id-min-max-greater-than-1)`|`[<mark style="color:green;">`undefined`</mark>](https://www.typescriptlang.org/docs/handbook/basic-types.html#null-and-undefined)

### Returns

The **return value** is the minimum range of generic type variable [`Min`](/draft-5/rangeerror/generic-type-variables#rangeerror-less-than-id-min-max-greater-than-1) or [`undefined`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined).

## Example usage

```typescript
// Example usage.
import { RangeError } from '@angular-package/error';

// Returns "9".
new RangeError('problem', 'Fix accessor.', '(AE:427)', 9, 27).min;
```


# get name()

The \`get\` accessor obtains error name

## ​`RangeError.prototype.name`

The [`get`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/get) accessor obtains error name of a [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) type, set to `'RangeError'` that is being thrown.

{% code title="range-error.class.ts" %}

```typescript
public get name(): string {
  return 'RangeError';
}
```

{% endcode %}

### Return type

#### [<mark style="color:green;">`string`</mark>](https://www.typescriptlang.org/docs/handbook/basic-types.html#string)

### Returns

The **return value** is the error instance name of [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) type.

## Example usage

```typescript
// Example usage.
import { RangeError } from '@angular-package/error';

// Returns "RangeError".
new RangeError('problem', 'Fix accessor.').name;
```


# get range()

The \`get\` accessor obtains the range of minimum and maximum

## ​`RangeError.prototype.range`

The [`get`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/get) accessor obtains the [minimum](/draft-5/rangeerror/accessors/get-min) and [maximum](/draft-5/rangeerror/accessors/get-max) range in the form of an [object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object).

{% code title="range-error.class.ts" %}

```typescript
public get range(): { min?: Min; max?: Max } {
  return {
    min: this.#min,
    max: this.#max,
  };
}
```

{% endcode %}

### Return type

#### `{ min?:`[<mark style="color:green;">`Min`</mark>](/draft-5/rangeerror/generic-type-variables#rangeerror-less-than-id-min-max-greater-than-1)`; max?:`[<mark style="color:green;">`Max`</mark>](/draft-5/rangeerror/generic-type-variables#rangeerror-less-than-id-min-max-greater-than-2)`}`

The **return type** is the [`object`](https://www.typescriptlang.org/docs/handbook/basic-types.html#object) that consists of the `min` and `max` properties, indicating the error range.

### Returns

The **return value** is an [`object`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object) that consists of the [minimum](/draft-5/rangeerror/accessors/get-min) range under the `min` property and the [maximum](/draft-5/rangeerror/accessors/get-max) under the `max` property.

`min` - The minimum range of generic type variable [`Min`](/draft-5/rangeerror/generic-type-variables#rangeerror-less-than-id-min-max-greater-than-1) of the [`RangeError`](/draft-5/rangeerror/overview) instance.\
`max` - The maximum range of generic type variable [`Max`](/draft-5/rangeerror/generic-type-variables#rangeerror-less-than-id-min-max-greater-than-2) of the [`RangeError`](/draft-5/rangeerror/overview) instance.

## Example usage

```typescript
// Example usage.
import { RangeError } from '@angular-package/error';

// Returns "{min: 9, max: 27}".
new RangeError('problem', 'Fix accessor.', '(AE:427)', 9, 27).range;
```


# get \[Symbol.toStringTag]\()

Changes the default tag to 'RangeError' for an instance

## `[Symbol.toStringTag]()`

The [`get`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/get) accessor, with the help of [`toStringTag`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toStringTag), changes the default tag to `'RangeError'` for an instance of [`RangeError`](/draft-5/rangeerror/overview).

It can be read by the [`typeOf()`](https://docs.angular-package.dev/v/type/helper/typeof) function of [`@angular-package/type`](https://docs.angular-package.dev/v/type/).

{% code title="range-error.class.ts" %}

```typescript
public get [Symbol.toStringTag](): string {
  return 'RangeError';
}
```

{% endcode %}

### Return type

#### [<mark style="color:green;">`string`</mark>](https://www.typescriptlang.org/docs/handbook/basic-types.html#string)

### Returns

The **return value** is the word `'RangeError'` of a [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String).

## Example usage

```typescript
// Example usage.
import { RangeError } from '@angular-package/error';
import { typeOf } from '@angular-package/type';

// Returns "rangeerror".
typeOf(new RangeError('problem', 'Fix accessor.'));
```


# Properties

The \`RangeError\` object properties

|                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| <p><strong>public static</strong> <a href="/pages/yqgr3HjFTyrXiV7yh0Xx"><strong>template</strong></a><strong>:</strong> <mark style="color:green;">string</mark><br>A template of the error message of <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String"><code>string</code></a> type with the replaceable <a href="/pages/akE6vknq8khSYhbok2vb#problem"><code>{problem}</code></a>, <a href="/pages/akE6vknq8khSYhbok2vb#fix"><code>{fix}</code></a> and optional <a href="/pages/akE6vknq8khSYhbok2vb#id"><code>{id}</code></a>, <a href="/pages/akE6vknq8khSYhbok2vb#max"><code>{max}</code></a>, <a href="/pages/akE6vknq8khSYhbok2vb#min"><code>{min}</code></a>, <a href="/pages/akE6vknq8khSYhbok2vb#type"><code>{type}</code></a> tags.</p> |
| <p><a href="/pages/BuTFE6zoCgaGuhnnIVFt"><strong>#max?</strong></a><strong>:</strong> <mark style="color:green;">Max</mark><br>Private property of the <a href="/pages/6Nle1uMltWSb2uh6hgTQ#range">maximum range</a> of generic type variable <a href="/pages/4o4mE7ENn7hKzuk12xAY#rangeerror-less-than-id-min-max-greater-than-2"><code>Max</code></a> that causes an error to be thrown(or not thrown).</p>                                                                                                                                                                                                                                                                                                                                                                                       |
| <p><a href="/pages/I2ne0dK2qnw4AnG6ML2h"><strong>#min?</strong></a><strong>:</strong> <mark style="color:green;">Min</mark><br>Private property of the <a href="/pages/6Nle1uMltWSb2uh6hgTQ#range">minimum range</a> of generic type variable <a href="/pages/4o4mE7ENn7hKzuk12xAY#rangeerror-less-than-id-min-max-greater-than-1"><code>Min</code></a> that causes an error to be thrown(or not thrown).</p>                                                                                                                                                                                                                                                                                                                                                                                       |


# static template

A template of the error message

## `RangeError.template`

A template of the error message of [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) type with the replaceable [`{problem}`](/draft-5/commonerror/properties/static-template#problem), [`{fix}`](/draft-5/commonerror/properties/static-template#fix) and optional [`{id}`](/draft-5/commonerror/properties/static-template#id), [`{max}`](/draft-5/commonerror/properties/static-template#max), [`{min}`](/draft-5/commonerror/properties/static-template#min) tags.

By default, it's set to `Problem{id}: {problem} => Fix: {fix} between {min} and {max}`.

{% code title="range-error.class.ts" %}

```typescript
public static template = `Problem{id}: {problem} must be between {min} and {max} => Fix: {fix}`;
```

{% endcode %}

## Example usage

```typescript
// Example usage.
import { RangeError } from '@angular-package/error'; 

// Change the template.
RangeError.template = `Problem({id}): {problem} => Fix: {fix}`;

// Returns
// RangeError: Problem((AE:427)): The `age` parameter is too big, got 455 => Fix: Set the `age` parameter of the `setAge()` method
new RangeError(
  'The `age` parameter is too big, got 455', // Problem
  'Set the `age` parameter of the `setAge()` method', // Fix
  '(AE:427)', // Identification
  9,  // Minimum
  27 // Maximum range
);
```


# #max?

Private property of the maximum range

## `#max?`

Private property of the [maximum range](/draft-5/getting-started/basic-concepts#range) of generic type variable [`Max`](/draft-5/rangeerror/generic-type-variables#rangeerror-less-than-id-min-max-greater-than-2) that causes an error to be thrown(or not thrown).

{% code title="range-error.class.ts" %}

```typescript
#max?: Max;
```

{% endcode %}

### Type

#### [<mark style="color:green;">`Max`</mark>](/draft-5/rangeerror/generic-type-variables#rangeerror-less-than-id-min-max-greater-than-2)


# #min?

Private property of the minimum range

## `#min?`

Private property of the [minimum range](/draft-5/getting-started/basic-concepts#range) of generic type variable [`Min`](/draft-5/rangeerror/generic-type-variables#rangeerror-less-than-id-min-max-greater-than-1) that causes an error to be thrown(or not thrown).

{% code title="range-error.class.ts" %}

```typescript
#min?: Min;
```

{% endcode %}

### Type

#### [<mark style="color:green;">`Min`</mark>](/draft-5/rangeerror/generic-type-variables#rangeerror-less-than-id-min-max-greater-than-1)


# Methods

The \`RangeError\` object methods

|                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| <p><strong>public static</strong> <a href="/pages/pIRw6dz385L7OxhSnFpa"><strong>define()</strong></a><strong>:</strong> <mark style="color:green;">RangeError</mark><<mark style="color:green;">Id</mark>, <mark style="color:green;">Min</mark>, <mark style="color:green;">Max</mark>><br>Defines the <a href="/pages/XTL5Khe1PhScTJnRkiDh"><code>RangeError</code></a> instance with the <a href="/pages/UAsNmVmOuYGxNypELFFh">message</a> built from the given required <a href="/pages/pIRw6dz385L7OxhSnFpa#problem-string"><code>problem</code></a>, <a href="/pages/pIRw6dz385L7OxhSnFpa#fix-string"><code>fix</code></a> and optional <a href="/pages/pIRw6dz385L7OxhSnFpa#id-id"><code>id</code></a>, <a href="/pages/pIRw6dz385L7OxhSnFpa#max-max"><code>max</code></a>, <a href="/pages/pIRw6dz385L7OxhSnFpa#min-min"><code>min</code></a> on the given or stored <a href="/pages/pIRw6dz385L7OxhSnFpa#template-rangeerror.template"><code>template</code></a>.</p> |
| <p><strong>public static</strong> <a href="/pages/lUISc8abHJfLgsx2BRMZ"><strong>isRangeError()</strong></a><strong>:</strong> value is <mark style="color:green;">RangeError</mark><<mark style="color:green;">Id</mark>, <mark style="color:green;">Min</mark>, <mark style="color:green;">Max</mark>><br>Checks whether the <a href="/pages/lUISc8abHJfLgsx2BRMZ#value-any"><code>value</code></a> of <a href="https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#any"><code>any</code></a> type is an instance of <a href="/pages/XTL5Khe1PhScTJnRkiDh"><code>RangeError</code></a> of any or the given <a href="/pages/lUISc8abHJfLgsx2BRMZ#min-min">minimum</a>/<a href="/pages/lUISc8abHJfLgsx2BRMZ#max-max">maximum</a> range and <a href="/pages/lUISc8abHJfLgsx2BRMZ#id-id">identification</a>.</p>                                                                                                                                                   |


# static define()

Defines the \`RangeError\` instance.

## `RangeError.define()`

Defines the [`RangeError`](/draft-5/rangeerror/overview) instance with the [message](/draft-5/commonerror/accessors/get-message) built from the given required [`problem`](#problem-string), [`fix`](#fix-string) and optional [`id`](#id-id), [`max`](#max-max), [`min`](#min-min) on the given or stored [`template`](#template-rangeerror.template).

{% code title="range-error.class.ts" %}

```typescript
public static define<
  Id extends string,
  Min extends number | undefined = undefined,
  Max extends number | undefined = undefined
>(
  problem: string,
  fix: string,
  id?: Id,
  min?: Min,
  max?: Max,
  template = RangeError.template
): RangeError<Id, Min, Max> {
  return new this(problem, fix, id, min, max, template);
}
```

{% endcode %}

### Generic type variables

#### <mark style="color:green;">`Id`</mark>`extends`[<mark style="color:green;">`string`</mark>](https://www.typescriptlang.org/docs/handbook/basic-types.html#string)

A generic type variable constrained by the [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String), by default of the value **captured** from the provided optional [`id`](#id-id) indicates the [identification](/draft-5/getting-started/basic-concepts#identification) type of a new [`RangeError`](/draft-5/rangeerror/overview) instance.

#### <mark style="color:green;">`Min`</mark>`extends`[<mark style="color:green;">`number`</mark>](https://www.typescriptlang.org/docs/handbook/basic-types.html#number)`|`[<mark style="color:green;">`undefined`</mark>](https://www.typescriptlang.org/docs/handbook/basic-types.html#null-and-undefined)`=`<mark style="color:green;">`undefined`</mark>

A generic type variable constrained by the [`number`](https://www.typescriptlang.org/docs/handbook/basic-types.html#number) and [`undefined`](https://www.typescriptlang.org/docs/handbook/basic-types.html#null-and-undefined), by default of the value equal to [`undefined`](https://www.typescriptlang.org/docs/handbook/basic-types.html#null-and-undefined) indicates the captured type of the supplied [`min`](#min-min) via the [return type](#return-type).

#### <mark style="color:green;">`Max`</mark>`extends`[<mark style="color:green;">`number`</mark>](https://www.typescriptlang.org/docs/handbook/basic-types.html#number)`|`<mark style="color:green;">`undefined`</mark>`=`<mark style="color:green;">`undefined`</mark>

A generic type variable constrained by the [`number`](https://www.typescriptlang.org/docs/handbook/basic-types.html#number) and [`undefined`](https://www.typescriptlang.org/docs/handbook/basic-types.html#null-and-undefined), by default of the value equal to [`undefined`](https://www.typescriptlang.org/docs/handbook/basic-types.html#null-and-undefined) indicates the captured type of the supplied [`max`](#max-max) via the [return type](#return-type).

### Parameters

#### `problem:`[<mark style="color:green;">`string`</mark>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)

Description of the [problem](#problem-string) of a [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) type.

#### `fix:`[<mark style="color:green;">`string`</mark>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)

A solution to the given [`problem`](#problem-string) of a [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) type.

#### `id?:`[<mark style="color:green;">`Id`</mark>](#idextendsstring)

Optional unique [identification](/draft-5/getting-started/basic-concepts#identification) to the given [`problem`](#problem-string) of generic type variable [`Id`](#idextendsstring).

#### `min?:`[<mark style="color:green;">`Min`</mark>](#minextendsnumber-or-undefined-undefined)

The optional minimum range of generic type variable [`Min`](#minextendsnumber-or-undefined-undefined) that causes an error to be thrown(or not thrown).

#### `max?:`[<mark style="color:green;">`Max`</mark>](#maxextendsnumber-or-undefined-undefined)

The optional maximum range of generic type variable [`Max`](#maxextendsnumber-or-undefined-undefined) that causes an error to be thrown(or not thrown).

#### `template =`<mark style="color:green;">`RangeError`</mark>`.template`

A template of error message with the replaceable [`{problem}`](/draft-5/commonerror/properties/static-template#problem), [`{fix}`](/draft-5/commonerror/properties/static-template#fix) and optional [`{id}`](/draft-5/commonerror/properties/static-template#id), [`{max}`](/draft-5/commonerror/properties/static-template#max), [`{min}`](/draft-5/commonerror/properties/static-template#min) tags. By default, the value is equal to the static property [`RangeError.template`](/draft-5/rangeerror/properties/static-template).

### Return type

#### `RangeError<`[<mark style="color:green;">`Id`</mark>](#idextendsstring)`,`[<mark style="color:green;">`Min`</mark>](#minextendsnumber-or-undefined-undefined)`,`[<mark style="color:green;">`Max`</mark>](#maxextendsnumber-or-undefined-undefined)`>`

The **return type** is the [`RangeError`](/draft-5/rangeerror/overview) object that takes generic type variable [`Id`](#idextendsstring) as identification, [`Min`](#minextendsnumber-or-undefined-undefined) as minimum range and [`Max`](#maxextendsnumber-or-undefined-undefined) as maximum range.

### Returns

The **return value** is a new instance of the [`RangeError`](/draft-5/rangeerror/overview) with the [message](/draft-5/commonerror/accessors/get-message) built from the given required [`problem`](#problem-string), [`fix`](#fix-string) and optional [`id`](#id-id), [`min`](#min-min), [`max`](#max-max) on the given or stored [`template`](#template-rangeerror.template).

## Example usage

```typescript
// Example usage.
import { RangeError } from '@angular-package/error';

// Returns
// RangeError: ProblemTE:201: Wrong age => Fix: The value must be between 9 and 27
RangeError.define('Wrong age', 'The value must be', 'TE:201', 9, 27);
```


# static isRangeError()

Checks whether the value of any type is an instance of \`RangeError\`.

## `RangeError.isRangeError()`

Checks whether the [`value`](#value-any) of [`any`](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#any) type is an instance of [`RangeError`](/draft-5/rangeerror/overview) of any or the given [minimum](#min-number)/[maximum](#max-number) range and [identification](#id-id).

{% code title="range-error.class.ts" %}

```typescript
public static isRangeError<
  Id extends string,
  Min extends number | undefined = undefined,
  Max extends number | undefined = undefined
>(
  value: any,
  id?: Id,
  min?: Min,
  max?: Max
): value is RangeError<Id, Min, Max> {
  return (
    super.isError(value, id) &&
    (typeof min === 'number' ? (value as any).min === min : true) &&
    (typeof max === 'number' ? (value as any).max === max : true)
  );
}
```

{% endcode %}

### Generic type variables

#### <mark style="color:green;">`Id`</mark>`extends`[<mark style="color:green;">`string`</mark>](https://www.typescriptlang.org/docs/handbook/basic-types.html#string)

A generic type variable constrained by the [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String), by default of the value **captured** from the provided optional [`id`](#id-id) indicates the [identification](/draft-5/getting-started/basic-concepts#identification) type of the [`RangeError`](/draft-5/rangeerror/overview) via [return type](#return-type).

#### <mark style="color:green;">`Min`</mark>`extends`[<mark style="color:green;">`number`</mark>](https://www.typescriptlang.org/docs/handbook/basic-types.html#number)`|`[<mark style="color:green;">`undefined`</mark>](https://www.typescriptlang.org/docs/handbook/basic-types.html#null-and-undefined)`=`<mark style="color:green;">`undefined`</mark>

A generic type variable constrained by the [`number`](https://www.typescriptlang.org/docs/handbook/basic-types.html#number) and [`undefined`](https://www.typescriptlang.org/docs/handbook/basic-types.html#null-and-undefined), by default of the value equal to [`undefined`](https://www.typescriptlang.org/docs/handbook/basic-types.html#null-and-undefined) indicates the captured type of the supplied [`min`](#min-min) via the [return type](#return-type).

#### <mark style="color:green;">`Max`</mark>`extends`[<mark style="color:green;">`number`</mark>](https://www.typescriptlang.org/docs/handbook/basic-types.html#number)`|`<mark style="color:green;">`undefined`</mark>`=`<mark style="color:green;">`undefined`</mark>

A generic type variable constrained by the [`number`](https://www.typescriptlang.org/docs/handbook/basic-types.html#number) and [`undefined`](https://www.typescriptlang.org/docs/handbook/basic-types.html#null-and-undefined), by default of the value equal to [`undefined`](https://www.typescriptlang.org/docs/handbook/basic-types.html#null-and-undefined) indicates the captured type of the supplied [`max`](#max-max) via the [return type](#return-type).

### Parameters

#### `value:`[<mark style="color:green;">`any`</mark>](https://www.typescriptlang.org/docs/handbook/basic-types.html#any)

The value of [`any`](https://www.typescriptlang.org/docs/handbook/basic-types.html#any) type to check against the [`RangeError`](/draft-5/rangeerror/overview) instance.

#### `id?:`[<mark style="color:green;">`Id`</mark>](#idextendsstring)

Optional unique [identification](/draft-5/getting-started/basic-concepts#identification) of generic type variable [`Id`](#idextendsstring) to check whether the given [`value`](#value-any) contains.

#### `min?:`[<mark style="color:green;">`Min`</mark>](#minextendsnumber-or-undefined-undefined)

The optional minimum range of generic type variable [`Min`](#minextendsnumber-or-undefined-undefined) that causes an error to be thrown(or not thrown) to check whether the given [`value`](#value-any) contains.

#### `max?:`[<mark style="color:green;">`Max`</mark>](#maxextendsnumber-or-undefined-undefined)

The optional minimum range of generic type variable [`Max`](#maxextendsnumber-or-undefined-undefined) that causes an error to be thrown(or not thrown) to check whether the given [`value`](#value-any) contains.

### Return type

#### `value is RangeError<`[<mark style="color:green;">`Id`</mark>](#idextendsstring)`,`[<mark style="color:green;">`Min`</mark>](#minextendsnumber-or-undefined-undefined)`,`[<mark style="color:green;">`Max`</mark>](#maxextendsnumber-or-undefined-undefined)`>`

The **return type** is a [`boolean`](https://www.typescriptlang.org/docs/handbook/basic-types.html#boolean) resulting from its statement indicating the [`value`](#value-any) is the [`RangeError`](/draft-5/rangeerror/overview) object that takes the generic type variable [`Id`](#idextendsstring) as identification, [`Min`](#minextendsnumber-or-undefined-undefined) as minimum range and [`Max`](#maxextendsnumber-or-undefined-undefined) as maximum range.

### Returns

The **return value** is a [`boolean`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean) type indicating whether the given [`value`](#value-any) is an instance of [`RangeError`](/draft-5/rangeerror/overview) of any or the given optional [`min`](#min-min), [`max`](#max-max) and [`id`](#id-id) properties.

## Example usage

```typescript
// Example usage.
import { RangeError } from '@angular-package/error';

// Define error.
const err = RangeError.define('Wrong type', 'Change the type', 'TE:201', 9, 27);

// Returns true.
RangeError.isRangeError(err);

// Returns true.
RangeError.isRangeError(err, 'TE:201');

// Returns false.
RangeError.isRangeError(err, 'TE:202', 9);

// Returns false.
RangeError.isRangeError(err, 'TE:202', 9, 27);

// Returns false.
RangeError.isRangeError(new Array());
```


# Overview

The \`RangeErrors\` object

## `RangeErrors {}`

The `RangeErrors` is an extension of the [`CommonErrors`](/draft-5/commonerrors/overview) object that represents multiple identification numbers under which the errors of the [`RangeError`](/draft-5/rangeerror/overview) type are prepared to throw.

{% embed url="<https://github.com/angular-package/error/blob/main/src/lib/range-errors.class.ts>" %}
`range-errors.class.ts`
{% endembed %}

### Methods

|                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |                                                                                                                                                                                                                                                                                                                                                                                                      |
| --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| <p><strong>public</strong> <a href="/pages/E9AYZVTtEkge0O7KtPhU"><strong>get()</strong></a>: <mark style="color:green;">RangeError</mark><<mark style="color:green;">ErrorId</mark>>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          | <mark style="color:green;">undefined</mark><br>Returns the <a href="/pages/XTL5Khe1PhScTJnRkiDh"><code>RangeError</code></a> instance of the given unique identification <a href="/pages/E9AYZVTtEkge0O7KtPhU#id-errorid"><code>id</code></a> if set, otherwise <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined"><code>undefined</code></a>.</p> |
| <p><strong>public</strong> <a href="/pages/i0vDnRi1CNeWGBBEb7Sx"><strong>getErrors()</strong></a>: { \[<mark style="color:green;">Key</mark> in <mark style="color:green;">Id</mark>]: <mark style="color:green;">RangeError</mark><<mark style="color:green;">Key</mark>>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    | <mark style="color:green;">undefined</mark> }<br>Returns an <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object"><code>object</code></a> of set range errors, where the key is a <a href="/pages/6Nle1uMltWSb2uh6hgTQ#unique-identification">unique identification</a>.</p>                                                                             |
| <p><strong>public</strong> <a href="/pages/tPGpxe2ljDxrbFB5Te4M"><strong>set()</strong></a><strong>:</strong> <mark style="color:green;">this</mark><br>Sets the <a href="/pages/XTL5Khe1PhScTJnRkiDh"><code>RangeError</code></a> object with the message built from the given required <a href="/pages/tPGpxe2ljDxrbFB5Te4M#problem-string"><code>problem</code></a>, <a href="/pages/tPGpxe2ljDxrbFB5Te4M#fix-string"><code>fix</code></a>, <a href="/pages/tPGpxe2ljDxrbFB5Te4M#id-errorid"><code>id</code></a>, and optional <a href="/pages/tPGpxe2ljDxrbFB5Te4M#min-number"><code>min</code></a>, <a href="/pages/tPGpxe2ljDxrbFB5Te4M#max-number"><code>max</code></a> on the given or stored <a href="/pages/tPGpxe2ljDxrbFB5Te4M#template-rangeerrors.template"><code>template</code></a> under the given <a href="/pages/tPGpxe2ljDxrbFB5Te4M#id-errorid"><code>id</code></a>.</p> |                                                                                                                                                                                                                                                                                                                                                                                                      |


# Generic type variables

The \`RangeErrors\` object generic type variables

## `RangeErrors<`<mark style="color:green;background-color:green;">`Id`</mark>`>`

#### <mark style="color:green;">`Id`</mark>`extends`[<mark style="color:green;">`string`</mark>](https://www.typescriptlang.org/docs/handbook/basic-types.html#string)

​A generic type variable constrained by the [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String), by default of the value **captured** from the provided [rest parameter](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/rest_parameters) [`id`](https://error.angular-package.dev/draft-5/rangeerrors/pages/2OPOWk5JYwYC6Zd5cbL7#...id-id) indicates the identification type of a new [`RangeErrors`](/draft-5/rangeerrors/overview) instance.

{% code title="range-errors.class.ts" %}

```typescript
class RangeErrors<
  Id extends string // <--- Declare generic type variable Id.
> extends CommonErrors<Id> {
  constructor(
    ...id: Id[] // <--- Capture generic type variable Id.
  ) {
    super(...id);
  }
}
```

{% endcode %}


# Constructor

The \`RangeErrors\` constructor

## `RangeErrors()`

Creates the [`RangeErrors`](/draft-5/rangeerrors/overview) instance of [unique identification](/draft-5/getting-started/basic-concepts#unique-identification) numbers under which the [`RangeError`](/draft-5/rangeerror/overview) objects are stored.

{% code title="range-errors.class.ts" %}

```typescript
constructor(...id: Id[]) {
  super(...id);
}
```

{% endcode %}

### Parameters

#### `...id:`[<mark style="color:green;">`Id`</mark>](/draft-5/rangeerrors/generic-type-variables#rangeerrors-less-than-id-greater-than)`[]`

A [rest parameter](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/rest_parameters) of generic type variable [`Id`](/draft-5/rangeerrors/generic-type-variables#rangeerrors-less-than-id-greater-than) indicates [unique identification](/draft-5/getting-started/basic-concepts#unique-identification) numbers under which the [`RangeError`](/draft-5/rangeerror/overview) objects are stored.

## Example usage

```typescript
// Example usage.
import { RangeErrors } from '@angular-package/error';

// Returns RangeErrors {}
new RangeErrors('RE: 4332', 'RE: 4331', 'RE: 4330');

// Returns RangeErrors {}
new RangeErrors('RV: 332', 'RV: 331', 'RV: 330');
```


# Methods

The \`RangeErrors\` object methods

|                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |                                                                                                                                                                                                                                                                                                                                                                                                      |
| --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| <p><strong>public</strong> <a href="/pages/E9AYZVTtEkge0O7KtPhU"><strong>get()</strong></a>: <mark style="color:green;">RangeError</mark><<mark style="color:green;">ErrorId</mark>>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          | <mark style="color:green;">undefined</mark><br>Returns the <a href="/pages/XTL5Khe1PhScTJnRkiDh"><code>RangeError</code></a> instance of the given unique identification <a href="/pages/E9AYZVTtEkge0O7KtPhU#id-errorid"><code>id</code></a> if set, otherwise <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined"><code>undefined</code></a>.</p> |
| <p><strong>public</strong> <a href="/pages/i0vDnRi1CNeWGBBEb7Sx"><strong>getErrors()</strong></a>: { \[<mark style="color:green;">Key</mark> in <mark style="color:green;">Id</mark>]: <mark style="color:green;">RangeError</mark><<mark style="color:green;">Key</mark>>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    | <mark style="color:green;">undefined</mark> }<br>Returns an <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object"><code>object</code></a> of set range errors, where the key is a <a href="/pages/6Nle1uMltWSb2uh6hgTQ#unique-identification">unique identification</a>.</p>                                                                             |
| <p><strong>public</strong> <a href="/pages/tPGpxe2ljDxrbFB5Te4M"><strong>set()</strong></a><strong>:</strong> <mark style="color:green;">this</mark><br>Sets the <a href="/pages/XTL5Khe1PhScTJnRkiDh"><code>RangeError</code></a> object with the message built from the given required <a href="/pages/tPGpxe2ljDxrbFB5Te4M#problem-string"><code>problem</code></a>, <a href="/pages/tPGpxe2ljDxrbFB5Te4M#fix-string"><code>fix</code></a>, <a href="/pages/tPGpxe2ljDxrbFB5Te4M#id-errorid"><code>id</code></a>, and optional <a href="/pages/tPGpxe2ljDxrbFB5Te4M#min-number"><code>min</code></a>, <a href="/pages/tPGpxe2ljDxrbFB5Te4M#max-number"><code>max</code></a> on the given or stored <a href="/pages/tPGpxe2ljDxrbFB5Te4M#template-rangeerrors.template"><code>template</code></a> under the given <a href="/pages/tPGpxe2ljDxrbFB5Te4M#id-errorid"><code>id</code></a>.</p> |                                                                                                                                                                                                                                                                                                                                                                                                      |


# get()

Returns the \`RangeError\` instance of the given unique identification

## `RangeErrors.prototype.get()`

Returns the [`RangeError`](/draft-5/rangeerror/overview) instance of the given [unique identification](/draft-5/getting-started/basic-concepts#unique-identification) [`id`](#id-errorid) if set, otherwise [`undefined`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined).

{% code title="range-errors.class.ts" %}

```typescript
public get<ErrorId extends Id>(id: ErrorId): RangeError<ErrorId> | undefined {
  return this.errors.get(id);
}
```

{% endcode %}

### Generic type variables

#### <mark style="color:green;">`ErrorId`</mark>`extends`[<mark style="color:green;">`Id`</mark>](/draft-5/rangeerrors/generic-type-variables#rangeerrors-less-than-id-greater-than)

A generic type variable `ErrorId` constrained by the generic type variable [`Id`](/draft-5/rangeerrors/generic-type-variables#rangeerrors-less-than-id-greater-than) of the [`Errors`](/draft-5/errors/overview) object indicates the type picked from the [`Id`](/draft-5/rangeerrors/generic-type-variables#rangeerrors-less-than-id-greater-than) and its exact type is useful in picking the specific range error from the storage.

### Parameters

#### `id:`[<mark style="color:green;">`ErrorId`</mark>](#erroridextendsid)

The [unique identification](/draft-5/getting-started/basic-concepts#unique-identification) number of generic type variable [`ErrorId`](#erroridextendsid) to pick an error from the object.

### Return type

#### `RangeError<`[<mark style="color:green;">`ErrorId`</mark>](#erroridextendsid)`> |`[<mark style="color:green;">`undefined`</mark>](https://www.typescriptlang.org/docs/handbook/basic-types.html#null-and-undefined)

The **return type** is the [`RangeError`](/draft-5/rangeerror/overview) object that takes the generic type variable [`ErrorId`](#erroridextendsid) or [`undefined`](https://www.typescriptlang.org/docs/handbook/basic-types.html#null-and-undefined).

### Returns

The **return value** is the [`RangeError`](/draft-5/rangeerror/overview) instance of the given [`id`](#id-errorid) if set, otherwise [`undefined`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined).

## Example usage

```typescript
// Example usage.
import { RangeErrors } from '@angular-package/error';

// Define range errors.
const rangeErrors = new RangeErrors('(RE: 4332)', '(RE: 4331)', '(RE: 4330)');

// Set the `RangeError` objects under the given identification numbers.
rangeErrors
  .set(
    'Age is 99',
    'Age must be',
    '(RE: 4330)',
    9,
    27
  )
  .set('Height can not be 11000', 'Height', '(RE: 4331)', 1, 1000);

// Returns RangeError: Problem(RE: 4330): Age is 99 => Fix: Age must be must be between 9 and 27
// of type RangeError<"EG: 4330", undefined, undefined> | undefined.
rangeErrors.get('RE: 4330');
```


# getErrors()

Returns the object of set errors

## `RangeErrors.prototype.getErrors()`

Returns an [`object`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object) of set range errors, where the key is a [unique identification](/draft-5/getting-started/basic-concepts#unique-identification).

{% code title="range-errors.class.ts" %}

```typescript
public getErrors(): { [Key in Id]: RangeError<Key> | undefined } {
  return Object.fromEntries(this.errors.entries()) as any;
}
```

{% endcode %}

### Return type

#### `{ [`<mark style="color:green;">`Key`</mark>`in`[<mark style="color:green;">`Id`</mark>](/draft-5/rangeerrors/generic-type-variables#rangeerrors-less-than-id-greater-than)`]: RangeError<`<mark style="color:green;">`Key`</mark>`> |`<mark style="color:green;">`undefined`</mark>` ``}`

The **return type** is an object of the  [`RangeError`](/draft-5/rangeerror/overview) objects or [`undefined`](https://www.typescriptlang.org/docs/handbook/basic-types.html#null-and-undefined) in the keys of generic type variable [`Id`](/draft-5/rangeerrors/generic-type-variables#rangeerrors-less-than-id-greater-than).

### Returns

The **return value** is an [`object`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object) of set errors.

## Example usage

```typescript
// Example usage.
import { RangeErrors } from '@angular-package/error';

// Define range errors.
const rangeErrors = new RangeErrors('RE: 4332', 'RE: 4331', 'RE: 4330');

// Set the `RangeError` objects under the given identification numbers.
rangeErrors
  .set(
    'Age is 99',
    'Age must be',
    'RE: 4330',
    9,
    27
  )
  .set('Detected numbers', 'Provide only letters', 'RE: 4331');

/*
Returns
{
  RE: 4330: ...,
  RE: 4331: ...
}
of type
  {
    "RE: 4332": RangeError<"RE: 4332", undefined, undefined> | undefined;
    "RE: 4331": RangeError<"RE: 4331", undefined, undefined> | undefined;
    "RE: 4330": RangeError<"RE: 4330", undefined, undefined> | undefined;
  }
*/
rangeErrors.getErrors();
```


# set()

Sets the \`RangeError\` object under the given \`id\`

## `RangeErrors.prototype.set()`

Sets the [`RangeError`](/draft-5/rangeerror/overview) object with the message built from the given required [`problem`](#problem-string), [`fix`](#fix-string), [`id`](#id-errorid) and optional [`min`](#min-number), [`max`](#max-number) on the given or stored [`template`](#template-rangeerrors.template) under the given [`id`](#id-errorid).

{% code title="range-errors.class.ts" %}

```typescript
public set<ErrorId extends Id>(
  problem: string,
  fix: string,
  id: ErrorId,
  template = Errors.template
): this {
  this.isAllowedId(id) &&
    this.errors.set(id, new Error(problem, fix, id, template));
  return this;
}
```

{% endcode %}

### Generic type variables

#### <mark style="color:green;">`ErrorId`</mark>`extends`[<mark style="color:green;">`Id`</mark>](/draft-5/rangeerrors/generic-type-variables#rangeerrors-less-than-id-greater-than)

A generic type variable `ErrorId` constrained by the generic type variable [`Id`](/draft-5/rangeerrors/generic-type-variables#rangeerrors-less-than-id-greater-than) of the [`RangeErrors`](/draft-5/rangeerrors/overview) object indicates the type picked from the [`Id`](/draft-5/rangeerrors/generic-type-variables#rangeerrors-less-than-id-greater-than) and its exact type is useful in picking the specific error from the storage.

### Parameters

#### `problem:`[<mark style="color:green;">`string`</mark>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)

Description of the problem of a [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) type.

#### `fix:`[<mark style="color:green;">`string`</mark>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)

A solution to the given [`problem`](#problem-string) of a [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) type.

#### `id:`[<mark style="color:green;">`ErrorId`</mark>](#erroridextendsid)

The unique identification to the given [`problem`](#problem-string) of generic type variable [`ErrorId`](#erroridextendsid).

#### min?: [<mark style="color:green;">number</mark>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)

The optional minimum range of [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) type that causes an error to be thrown(or not thrown).

#### max?: [<mark style="color:green;">number</mark>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)

The optional maximum range of [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) type that causes an error to be thrown(or not thrown).

#### `template =`<mark style="color:green;">`RangeErrors`</mark>`.template`

A template of error message with the replaceable [`{problem}`](/draft-5/commonerror/properties/static-template#problem), [`{fix}`](/draft-5/commonerror/properties/static-template#fix),[`{id}`](/draft-5/commonerror/properties/static-template#id), and optional  [`{max}`](/draft-5/commonerror/properties/static-template#max), [`{min}`](/draft-5/commonerror/properties/static-template#min) tags. By default, the value is equal to the static property `RangeErrors.template`.

### Return type

#### <mark style="color:green;">`this`</mark>

## Example usage

```typescript
// Example usage.
import { RangeErrors } from '@angular-package/error';

// Define range errors.
const rangeErrors = new RangeErrors('RE: 4332', 'RE: 4331', 'RE: 4330');

// Set the `RangeError` objects under the given identification numbers.
rangeErrors
  .set(
    'Age is 99',
    'Age must be',
    'RE: 4330',
    9,
    27
  )
  .set('Detected numbers', 'Provide only letters', 'RE: 4331');
```


# Example usage

The \`RangeErrors\` object example usage

```typescript
// Example usage.
import { RangeErrors } from '@angular-package/error';

// Define range errors.
const rangeErrors = new RangeErrors('(RE: 4332)', '(RE: 4331)', '(RE: 4330)');
```

### `set()`

```typescript
// Set the `RangeError` objects under the given identification numbers.
rangeErrors
  .set('Age is 99', 'Age must be ', '(RE: 4330)', 9, 27)
  .set('Height can not be 11000', 'Set height ', '(RE: 4331)', 1, 1000)
  .set('Width can not be 300', 'Set width ', '(RE: 4331)', 1080, 1920);
```

### `delete()`

```typescript
// Example `delete()` method usage.
rangeErrors.delete('(RE: 4332)');
```

### `get()`

```typescript
// Example `get()` usage.

// Returns `undefined`.
rangeErrors.get('(RE: 4332)');

// Returns
// RangeError: Problem(RE: 4331): Width can not be 300 => Fix: Set width  between 1080 and 1920
rangeErrors.get('(RE: 4331)');
```

### `has()`

```typescript
// Example `has()` usage.

// Returns `false`.
rangeErrors.has('(RE: 4332)');

// Returns `true`.
rangeErrors.has('(RE: 4331)');
```

### `throw()`

```typescript
// Example `throw()` usage.
try {
  rangeErrors.throw('(RE: 4330)');
} catch (e) {
  if (RangeError.isRangeError(e)) {
    e.fix; // Age must be
    e.message; // Problem(RE: 4330): Age is 99 => Fix: Age must be  between 9 and 27
    e.name; // RangeError
    e.problem; // Age is 99
    e.template; // Problem{id}: {problem} => Fix: {fix} between {min} and {max}
    e.id; // (RE: 4330)
  }
}
```


# Overview

The \`TypeError\` object

## `TypeError {}`

The `TypeError` object is an extension of the [`CommonError`](/draft-5/commonerror/overview) class and is thrown when an operation could not be performed, typically(but not exclusively) when a value is not of the expected type, with the [message](/draft-5/commonerror/accessors/get-message) built from the described problem and its solution, optional an explicit identification and type, on the given or stored template.

{% embed url="<https://github.com/angular-package/error/blob/main/src/lib/type-error.class.ts>" %}
`type-error.class.ts`
{% endembed %}

### Accessors

|                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| <p><strong>public get</strong> <a href="/pages/8UioFWzm5LJ1elknzrYe"><strong>name()</strong></a><strong>:</strong> <mark style="color:green;">string</mark><br>The <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/get"><code>get</code></a> accessor obtains error name of a <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String"><code>string</code></a> type, set to <code>'TypeError'</code> that is being thrown.</p>                                                                                                                                                                                                                                |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| <p><strong>public get</strong> <a href="/pages/IhLrNl9T8KYkG5vkAAt3"><strong>type()</strong></a><strong>:</strong> <mark style="color:green;">Type</mark>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   | <mark style="color:green;">undefined</mark><br>The <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/get"><code>get</code></a> accessor obtains the type of generic type variable <a href="/pages/tS90ApbzGwGJToU8ZfRO#typeerror-less-than-id-type-greater-than-1"><code>Type</code></a> that causes an error to be thrown(or not thrown) if set, otherwise returns <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined"><code>undefined</code></a>.</p> |
| <p><strong>public get</strong> <a href="/pages/YgNE53pYCtwpY8A6ew6C"><strong>[Symbol.</strong><mark style="color:blue;"><strong>toStringTag</strong></mark><strong>](https://error.angular-package.dev/draft-5/typeerror)</strong></a><strong>:</strong> <mark style="color:green;">string</mark><br>The <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/get"><code>get</code></a> accessor, with the help of <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toStringTag"><code>toStringTag</code></a>, changes the default tag to <code>'TypeError'</code> for an instance of <a href="/pages/wXU3s9b3bJiG5x5vWa8P"><code>TypeError</code></a>.</p> |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |

### Properties

|                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| <p><strong>public static</strong> <a href="/pages/n0czl2edLCTym2DfgHEY"><strong>template</strong></a><strong>:</strong> <mark style="color:green;">string</mark><br>A template of the error message of <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String"><code>string</code></a> type with the replaceable <a href="/pages/akE6vknq8khSYhbok2vb#problem"><code>{problem}</code></a>, <a href="/pages/akE6vknq8khSYhbok2vb#fix"><code>{fix}</code></a> and optional <a href="/pages/akE6vknq8khSYhbok2vb#id"><code>{id}</code></a>, <a href="/pages/akE6vknq8khSYhbok2vb#max"><code>{max}</code></a>, <a href="/pages/akE6vknq8khSYhbok2vb#min"><code>{min}</code></a>, <a href="/pages/akE6vknq8khSYhbok2vb#type"><code>{type}</code></a> tags.</p> |
| <p><a href="/pages/omlavXNL7hQ5B4ZtEkA1"><strong>#type?</strong></a><strong>:</strong> <mark style="color:green;">string</mark><br>Private <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string-type</a> property of the type that causes an error to be thrown(or not thrown).</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                             |

### Methods

|                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| <p><strong>public static</strong> <a href="/pages/QO0W5kr9Si42Q6UmxCju"><strong>define()</strong></a><strong>:</strong> <mark style="color:green;">TypeError</mark><<mark style="color:green;">Id</mark>, <mark style="color:green;">Type</mark>><br>Defines the <a href="/pages/wXU3s9b3bJiG5x5vWa8P"><code>TypeError</code></a> instance with the <a href="/pages/UAsNmVmOuYGxNypELFFh">message</a> built of the given required <a href="/pages/QO0W5kr9Si42Q6UmxCju#problem-string"><code>problem</code></a>, <a href="/pages/QO0W5kr9Si42Q6UmxCju#fix-string"><code>fix</code></a> and optional <a href="/pages/QO0W5kr9Si42Q6UmxCju#id-id"><code>id</code></a> and <a href="/pages/QO0W5kr9Si42Q6UmxCju#type-type"><code>type</code></a> on the given or stored <a href="/pages/QO0W5kr9Si42Q6UmxCju#template-typeerror.template"><code>template</code></a>.</p> |
| <p><strong>public static</strong> <a href="/pages/LgNTaulQwQU9AGxOKSbU"><strong>isTypeError()</strong></a><strong>:</strong> value is <mark style="color:green;">TypeError</mark><<mark style="color:green;">Id</mark>, <mark style="color:green;">Type</mark>><br>Checks whether the <a href="/pages/LgNTaulQwQU9AGxOKSbU#value-any"><code>value</code></a> of <a href="https://www.typescriptlang.org/docs/handbook/basic-types.html#any"><code>any</code></a> type is an instance of <a href="/pages/wXU3s9b3bJiG5x5vWa8P"><code>TypeError</code></a> of any or the given <a href="/pages/LgNTaulQwQU9AGxOKSbU#type-type"><code>type</code></a> and <a href="/pages/LgNTaulQwQU9AGxOKSbU#id-id">identification</a>.</p>                                                                                                                                            |


# Generic type variables

The \`TypeError\` object generic type variables

## `TypeError<`<mark style="color:green;background-color:green;">`Id`</mark>`,Type>`

#### <mark style="color:green;">`Id`</mark>`extends`[<mark style="color:green;">`string`</mark>](https://www.typescriptlang.org/docs/handbook/basic-types.html#string)`=`[<mark style="color:green;">`string`</mark>](https://www.typescriptlang.org/docs/handbook/basic-types.html#string)

​A generic type variable constrained by the [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String), by default of the value **captured** from the provided [`id`](/draft-5/typeerror/constructor#id-id) indicates the identification type of a new [`TypeError`](/draft-5/typeerror/overview) instance.

{% code title="type-error.class.ts" %}

```typescript
class TypeError<
  Id extends string,  // <--- Declare generic type variable Id.
  Type extends string | undefined = undefined
> extends Error {
  ...
  constructor(
    problem: string,
    fix: string,
    id?: Id, // <--- Capture generic type variable Id.
    type?: Type,
    template = TypeError.template
  ) { ... }
  ...
}
```

{% endcode %}

## `TypeError<Id,`<mark style="color:green;background-color:green;">`Type`</mark>`>`

#### <mark style="color:green;">`Type`</mark>`extends`[<mark style="color:green;">`string`</mark>](https://www.typescriptlang.org/docs/handbook/basic-types.html#string)`|`[<mark style="color:green;">`undefined`</mark>](https://www.typescriptlang.org/docs/handbook/basic-types.html#null-and-undefined)`=`[<mark style="color:green;">`undefined`</mark>](https://www.typescriptlang.org/docs/handbook/basic-types.html#null-and-undefined)

A generic type variable constrained by the [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) and [`undefined`](https://www.typescriptlang.org/docs/handbook/basic-types.html#null-and-undefined), by default of the value equal to [`undefined`](https://www.typescriptlang.org/docs/handbook/basic-types.html#null-and-undefined) indicates the captured type of the supplied [`type`](/draft-5/typeerror/constructor#type-type) of a new [`TypeError`](/draft-5/typeerror/overview) instance.

{% code title="type-error.class.ts" %}

```typescript
class TypeError<
  Id extends string,
  Type extends string | undefined = undefined  // <--- Declare generic type variable Type.
> extends Error {
  ...
  constructor(
    problem: string,
    fix: string,
    id?: Id,
    type?: Type,  // <--- Capture generic type variable Type.
    template = TypeError.template
  ) { ... }
  ...
}
```

{% endcode %}


# ★ Constructor

The \`TypeError\` object constructor

## `TypeError()`

Creates a [`TypeError`](/draft-5/typeerror/overview) instance that represents type error with the [message](/draft-5/commonerror/accessors/get-message) built of the given described [problem](#problem-string) and its [solution](#fix-string), optional [type](#type-type), and an explicit [identification](#id-id) on the supplied or stored error message [template](#template-string-typeerror.template).

{% code title="type-error.class.ts" %}

```typescript
constructor(
  problem: string,
  fix: string,
  id?: Id,
  type?: Type,
  template = TypeError.template
) {
  super(problem, fix, id, template, { type });
  this.#type = type;
}
```

{% endcode %}

### Parameters

#### `problem:`[<mark style="color:green;">`string`</mark>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)

Description of the [problem](/draft-5/getting-started/basic-concepts#problem) of a [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) type.

#### `fix:`[<mark style="color:green;">`string`</mark>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)

A solution to the given [`problem`](#problem-string) of a [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) type.

#### `id?:`[<mark style="color:green;">`Id`</mark>](/draft-5/typeerror/generic-type-variables#wrap-opening)

Optional unique [identification](/draft-5/getting-started/basic-concepts#identification) to the given [`problem`](#problem-string) of generic type variable [`Id`](/draft-5/typeerror/generic-type-variables#typeerror-less-than-id-type-greater-than).

#### `type?:`[<mark style="color:green;">`Type`</mark>](/draft-5/typeerror/generic-type-variables#wrap-opening-1)

The optional type of generic type variable [`Type`](/draft-5/typeerror/generic-type-variables#typeerror-less-than-id-type-greater-than-1) that causes an error to be thrown(or not thrown).

#### `template:`[<mark style="color:green;">`string`</mark>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)`=`<mark style="color:green;">`TypeError`</mark>`.template`

Optional template of the error message of [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) type with the replaceable [`{problem}`](/draft-5/commonerror/properties/static-template#problem), [`{fix}`](/draft-5/commonerror/properties/static-template#fix) and optional [`{id}`](/draft-5/commonerror/properties/static-template#id), [`{type}`](/draft-5/commonerror/properties/static-template#type) tags. By default, the value is equal to the static property [`TypeError.template`](/draft-5/typeerror/properties/static-template).

## Example usage

```typescript
// Example usage.
import { TypeError } from '@angular-package/error';

// Returns
// TypeError: Problem(TE:201): Wrong type => Fix: The type of `age` parameter must be of the string
new TypeError('Wrong type', 'Change the type', '(TE:201)', 'string');
```


# Accessors

The \`TypeError\` object accessors

|                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| <p><strong>public get</strong> <a href="/pages/8UioFWzm5LJ1elknzrYe"><strong>name()</strong></a><strong>:</strong> <mark style="color:green;">string</mark><br>The <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/get"><code>get</code></a> accessor obtains error name of a <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String"><code>string</code></a> type, set to <code>'TypeError'</code> that is being thrown.</p>                                                                                                                                                                                                                                |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| <p><strong>public get</strong> <a href="/pages/IhLrNl9T8KYkG5vkAAt3"><strong>type()</strong></a><strong>:</strong> <mark style="color:green;">Type</mark>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   | <mark style="color:green;">undefined</mark><br>The <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/get"><code>get</code></a> accessor obtains the type of generic type variable <a href="/pages/tS90ApbzGwGJToU8ZfRO#typeerror-less-than-id-type-greater-than-1"><code>Type</code></a> that causes an error to be thrown(or not thrown) if set, otherwise returns <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined"><code>undefined</code></a>.</p> |
| <p><strong>public get</strong> <a href="/pages/YgNE53pYCtwpY8A6ew6C"><strong>[Symbol.</strong><mark style="color:blue;"><strong>toStringTag</strong></mark><strong>](https://error.angular-package.dev/draft-5/typeerror)</strong></a><strong>:</strong> <mark style="color:green;">string</mark><br>The <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/get"><code>get</code></a> accessor, with the help of <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toStringTag"><code>toStringTag</code></a>, changes the default tag to <code>'TypeError'</code> for an instance of <a href="/pages/wXU3s9b3bJiG5x5vWa8P"><code>TypeError</code></a>.</p> |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |


# get name()

The \`get\` accessor obtains error name

## `TypeError.prototype.name`

The [`get`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/get) accessor obtains error name of a [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) type, set to `'TypeError'` that is being thrown.

{% code title="type-error.class.ts" %}

```typescript
public get name(): string {
  return 'TypeError';
}
```

{% endcode %}

### Return type

#### [<mark style="color:green;">`string`</mark>](https://www.typescriptlang.org/docs/handbook/basic-types.html#string)

### Returns

The **return value** is the error instance name of [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) type.

## Example usage

```typescript
// Example usage.
import { TypeError } from '@angular-package/error';

// Returns "TypeError".
new TypeError('problem', 'Fix accessor.').name;
```


# get type()

The \`get\` accessor obtains the type

## ​`TypeError.prototype.type`

The [`get`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/get) accessor obtains the type of generic type variable [`Type`](/draft-5/typeerror/generic-type-variables#typeerror-less-than-id-type-greater-than-1) that causes an error to be thrown(or not thrown) if set, otherwise returns [`undefined`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined).

{% code title="type-error.class.ts" %}

```typescript
public get type(): Type | undefined {
  return this.#type;
}
```

{% endcode %}

### Return type

#### [<mark style="color:green;">`Type`</mark>](/draft-5/typeerror/generic-type-variables#typeerror-less-than-id-type-greater-than-1)`|`[<mark style="color:green;">`undefined`</mark>](https://www.typescriptlang.org/docs/handbook/basic-types.html#null-and-undefined)

### Returns

The **return value** is the type of generic type variable [`Type`](/draft-5/typeerror/generic-type-variables#typeerror-less-than-id-type-greater-than-1) or [`undefined`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined).

## Example usage

```typescript
// Example usage.
import { TypeError } from '@angular-package/error';

// Returns "string".
new TypeError('problem', 'Fix accessor.', '(TE:201)', 'string').type;
```


# get \[Symbol.toStringTag]\()

Changes the default tag to 'TypeError' for an instance

## `[Symbol.toStringTag]()`

The [`get`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/get) accessor, with the help of [`toStringTag`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toStringTag), changes the default tag to `'TypeError'` for an instance of [`TypeError`](/draft-5/typeerror/overview).

It can be read by the [`typeOf()`](https://docs.angular-package.dev/v/type/helper/typeof) function of [`@angular-package/type`](https://docs.angular-package.dev/v/type/).

{% code title="type-error.class.ts" %}

```typescript
public get [Symbol.toStringTag](): string {
  return 'TypeError';
}
```

{% endcode %}

### Return type

#### [<mark style="color:green;">`string`</mark>](https://www.typescriptlang.org/docs/handbook/basic-types.html#string)

### Returns

The **return value** is the word `'TypeError'` of a [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String).

## Example usage

```typescript
// Example usage.
import { TypeError } from '@angular-package/error';
import { typeOf } from '@angular-package/type';

// Returns "typeerror".
typeOf(new TypeError('problem', 'Fix accessor.'));
```


# Properties

The \`TypeError\` object properties

|                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| <p><strong>public static</strong> <a href="/pages/n0czl2edLCTym2DfgHEY"><strong>template</strong></a><strong>:</strong> <mark style="color:green;">string</mark><br>A template of the error message of <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String"><code>string</code></a> type with the replaceable <a href="/pages/akE6vknq8khSYhbok2vb#problem"><code>{problem}</code></a>, <a href="/pages/akE6vknq8khSYhbok2vb#fix"><code>{fix}</code></a> and optional <a href="/pages/akE6vknq8khSYhbok2vb#id"><code>{id}</code></a>, <a href="/pages/akE6vknq8khSYhbok2vb#max"><code>{max}</code></a>, <a href="/pages/akE6vknq8khSYhbok2vb#min"><code>{min}</code></a>, <a href="/pages/akE6vknq8khSYhbok2vb#type"><code>{type}</code></a> tags.</p> |
| <p><a href="/pages/omlavXNL7hQ5B4ZtEkA1"><strong>#type?</strong></a><strong>:</strong> <mark style="color:green;">string</mark><br>Private <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string-type</a> property of the type that causes an error to be thrown(or not thrown).</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                             |


# static template

A template of the error message

## `TypeError.template`

A template of the error message of [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) type with the replaceable [`{problem}`](/draft-5/commonerror/properties/static-template#problem), [`{fix}`](/draft-5/commonerror/properties/static-template#fix) and optional [`{id}`](/draft-5/commonerror/properties/static-template#id), [`{max}`](/draft-5/commonerror/properties/static-template#max), [`{min}`](/draft-5/commonerror/properties/static-template#min), [`{type}`](/draft-5/commonerror/properties/static-template#type) tags.

By default, it's set to `Problem{id}: {problem} => Fix: {fix} must be of the {type}`.

{% code title="type-error.class.ts" %}

```typescript
public static template = `Problem{id}: {problem} => Fix: {fix} must be of the {type}`;
```

{% endcode %}

## Example usage

```typescript
// Example usage.
import { TypeError } from '@angular-package/error'; 

// Change the template.
TypeError.template = `Problem({id}): {problem} => Fix: {fix}`;

// Returns
// TypeError: Problem(AE:427): The `age` parameter is wrong. => Fix: Provided `age` must be different type. 
new RangeError(
  'The `age` parameter is wrong.', // Problem
  'Provided `age` must be different type. ', // Fix
  'AE:427', // Identification
  'string',  // Type
);
```


# #type?

Private string-type property of the type that causes an error to be thrown(or not thrown)

## `#type?`

Private [string-type](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) property of the type that causes an error to be thrown(or not thrown).

{% code title="type-error.class.ts" %}

```typescript
#type?: string;
```

{% endcode %}

### Type

#### [<mark style="color:green;">`string`</mark>](https://www.typescriptlang.org/docs/handbook/basic-types.html#string)


# Methods

The \`TypeError\` object methods

|                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| <p><strong>public static</strong> <a href="/pages/QO0W5kr9Si42Q6UmxCju"><strong>define()</strong></a><strong>:</strong> <mark style="color:green;">TypeError</mark><<mark style="color:green;">Id</mark>, <mark style="color:green;">Type</mark>><br>Defines the <a href="/pages/wXU3s9b3bJiG5x5vWa8P"><code>TypeError</code></a> instance with the <a href="/pages/UAsNmVmOuYGxNypELFFh">message</a> built of the given required <a href="/pages/QO0W5kr9Si42Q6UmxCju#problem-string"><code>problem</code></a>, <a href="/pages/QO0W5kr9Si42Q6UmxCju#fix-string"><code>fix</code></a> and optional <a href="/pages/QO0W5kr9Si42Q6UmxCju#id-id"><code>id</code></a> and <a href="/pages/QO0W5kr9Si42Q6UmxCju#type-type"><code>type</code></a> on the given or stored <a href="/pages/QO0W5kr9Si42Q6UmxCju#template-typeerror.template"><code>template</code></a>.</p> |
| <p><strong>public static</strong> <a href="/pages/LgNTaulQwQU9AGxOKSbU"><strong>isTypeError()</strong></a><strong>:</strong> value is <mark style="color:green;">TypeError</mark><<mark style="color:green;">Id</mark>, <mark style="color:green;">Type</mark>><br>Checks whether the <a href="#value-any"><code>value</code></a> of <a href="https://www.typescriptlang.org/docs/handbook/basic-types.html#any"><code>any</code></a> type is an instance of <a href="/pages/wXU3s9b3bJiG5x5vWa8P"><code>TypeError</code></a> of any or the given <a href="#type-string"><code>type</code></a> and <a href="/pages/LgNTaulQwQU9AGxOKSbU#id-id">identification</a>.</p>                                                                                                                                                                                                |


# static define()

Defines the \`TypeError\` instance

## `TypeError.define()`

Defines the [`TypeError`](/draft-5/typeerror/overview) instance with the [message](/draft-5/commonerror/accessors/get-message) built of the given required [`problem`](#problem-string), [`fix`](#fix-string) and optional [`id`](#id-id) and [`type`](#type-string) on the given or stored [`template`](#template-typeerror.template).

{% code title="type-error.class.ts" %}

```typescript
public static define<
  Id extends string,
  Type extends string | undefined = undefined
>(
  problem: string,
  fix: string,
  id?: Id,
  type?: Type,
  template = TypeError.template
): TypeError<Id, Type> {
  return new this(problem, fix, id, type, template);
}
```

{% endcode %}

### Generic type variables

#### <mark style="color:green;">`Id`</mark>`extends`[<mark style="color:green;">`string`</mark>](https://www.typescriptlang.org/docs/handbook/basic-types.html#string)

A generic type variable constrained by the [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String), by default of the value **captured** from the provided optional [`id`](#id-id) indicates the [identification](/draft-5/getting-started/basic-concepts#identification) type of a new [`TypeError`](/draft-5/typeerror/overview) instance.

#### <mark style="color:green;">`Type`</mark>`extends`[<mark style="color:green;">`string`</mark>](https://www.typescriptlang.org/docs/handbook/basic-types.html#string)`|`[<mark style="color:green;">`undefined`</mark>](https://www.typescriptlang.org/docs/handbook/basic-types.html#null-and-undefined)`=`[<mark style="color:green;">`undefined`</mark>](https://www.typescriptlang.org/docs/handbook/basic-types.html#null-and-undefined)&#x20;

A generic type variable constrained by the [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) and [`undefined`](https://www.typescriptlang.org/docs/handbook/basic-types.html#null-and-undefined), by default of the value equal to [`undefined`](https://www.typescriptlang.org/docs/handbook/basic-types.html#null-and-undefined) indicates the captured type of the supplied [`type`](#type-type) of a new [`TypeError`](/draft-5/typeerror/overview) instance.

### Parameters

#### `problem:`[<mark style="color:green;">`string`</mark>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)

Description of the [problem](/draft-5/getting-started/basic-concepts#problem) of a [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) type.

#### `fix:`[<mark style="color:green;">`string`</mark>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)

A solution to the given [`problem`](#problem-string) of a [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) type.

#### `id?:`[<mark style="color:green;">`Id`</mark>](#idextendsstring)

Optional unique [identification](/draft-5/getting-started/basic-concepts#identification) to the given [`problem`](#problem-string) of generic type variable [`Id`](#idextendsstring).

#### `type?:`[<mark style="color:green;">`Type`</mark>](#typeextendsstring-or-undefined-undefined)

The optional type of generic type variable [`Type`](#typeextendsstring-or-undefined-undefined) that causes an error to be thrown(or not thrown).

#### `template =`<mark style="color:green;">`TypeError`</mark>`.template`

A template of error message with the replaceable [`{problem}`](/draft-5/commonerror/properties/static-template#problem), [`{fix}`](/draft-5/commonerror/properties/static-template#fix) and optional [`{id}`](/draft-5/commonerror/properties/static-template#id), [`{type}`](/draft-5/commonerror/properties/static-template#type) tags. By default, the value is equal to the static property [`TypeError.template`](/draft-5/typeerror/properties/static-template).

### Return type

#### `TypeError<`[<mark style="color:green;">`Id`</mark>](#idextendsstring)`,`[<mark style="color:green;">`Type`</mark>](#typeextendsstring-or-undefined-undefined)`>`

The **return type** is the [`TypeError`](/draft-5/typeerror/overview) object that takes generic type variable [`Id`](#idextendsstring) as identification and  generic type variable [`Type`](#typeextendsstring-or-undefined-undefined) as the type.

### Returns

The **return value** is a new instance of the [`TypeError`](/draft-5/typeerror/overview) with the [message](/draft-5/commonerror/accessors/get-message) built from the given required [`problem`](#problem-string), [`fix`](#fix-string) and optional [`id`](#id-id), [`type`](#type-type) on the given or stored [`template`](#template-typeerror.template).

## Example usage

```typescript
// Example usage.
import { TypeError } from '@angular-package/error';

// Returns
// TypeError: Problem(TE:201): Wrong type => Fix: The parameter age type must be of the string
TypeError.define('Wrong type', 'The parameter age type', '(TE:201)', 'string');
```


# static isTypeError()

Checks whether the value of any type is an instance of \`TypeError\`

## `TypeError.isTypeError()`

Checks whether the [`value`](#value-any) of [`any`](https://www.typescriptlang.org/docs/handbook/basic-types.html#any) type is an instance of [`TypeError`](/draft-5/typeerror/overview) of any or the given [`type`](#type-type) and [identification](#id-id).

{% code title="type-error.class.ts" %}

```typescript
public static isTypeError<
  Id extends string,
  Type extends string | undefined = undefined
>(value: any, id?: Id, type?: Type): value is TypeError<Id, Type> {
  return (
    super.isError(value, id) &&
    (typeof type === 'string' ? (value as any).type === type : true)
  );
}
```

{% endcode %}

### Generic type variables

#### <mark style="color:green;">`Id`</mark>`extends`[<mark style="color:green;">`string`</mark>](https://www.typescriptlang.org/docs/handbook/basic-types.html#string)

A generic type variable constrained by the [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String), by default of the value **captured** from the provided optional [`id`](#id-id) indicates the [identification](/draft-5/getting-started/basic-concepts#identification) type of the [`TypeError`](/draft-5/typeerror/overview) via [return type](#return-type).

#### <mark style="color:green;">`Type`</mark>`extends`[<mark style="color:green;">`string`</mark>](https://www.typescriptlang.org/docs/handbook/basic-types.html#string)`|`[<mark style="color:green;">`undefined`</mark>](https://www.typescriptlang.org/docs/handbook/basic-types.html#null-and-undefined)`=`[<mark style="color:green;">`undefined`</mark>](https://www.typescriptlang.org/docs/handbook/basic-types.html#null-and-undefined)&#x20;

A generic type variable constrained by the [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) and [`undefined`](https://www.typescriptlang.org/docs/handbook/basic-types.html#null-and-undefined), by default of the value equal to [`undefined`](https://www.typescriptlang.org/docs/handbook/basic-types.html#null-and-undefined) indicates the captured type of the supplied [`type`](#type-type) via [return type](#return-type).

### Parameters

#### `value:`[<mark style="color:green;">`any`</mark>](https://www.typescriptlang.org/docs/handbook/basic-types.html#any)

The value of [`any`](https://www.typescriptlang.org/docs/handbook/basic-types.html#any) type to check against the [`TypeError`](/draft-5/typeerror/overview) instance.

#### `id?:`[<mark style="color:green;">`Id`</mark>](#idextendsstring)

Optional unique [identification](/draft-5/getting-started/basic-concepts#identification) of generic type variable [`Id`](#idextendsstring) to check whether the given [`value`](#value-any) contains.

#### `type?:`[<mark style="color:green;">`Type`</mark>](#typeextendsstring-or-undefined-undefined)

The optional type of generic type variable [`Type`](#typeextendsstring-or-undefined-undefined) that causes an error to be thrown(or not thrown) to check whether the given [`value`](#value-any) contains.

### Return type

#### `value is TypeError<`[<mark style="color:green;">`Id`</mark>](#idextendsstring)`,`[<mark style="color:green;">`Type`</mark>](#typeextendsstring-or-undefined-undefined)`>`

The **return type** is a [`boolean`](https://www.typescriptlang.org/docs/handbook/basic-types.html#boolean) resulting from its statement indicating the [`value`](#value-any) is the [`TypeError`](/draft-5/typeerror/overview) object that takes the generic type variable [`Id`](#idextendsstring) as identification and generic type variable [`Type`](#typeextendsstring-or-undefined-undefined) as the type.

### Returns

The **return value** is a [`boolean`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean) type indicating whether the given [`value`](#value-any) is an instance of [`TypeError`](/draft-5/typeerror/overview) of any or the given optional [`type`](#type-type) and [`id`](#id-id) properties.

## Example usage

```typescript
// Example usage.
import { TypeError } from '@angular-package/error';

// Define error.
const err = TypeError.define('Wrong type', 'Change the type', 'TE:201', 'string');

// Returns true.
TypeError.isTypeError(err);

// Returns true.
TypeError.isTypeError(err, 'TE:201');

// Returns true.
TypeError.isTypeError(err, 'TE:201', 'string');

// Returns false.
TypeError.isTypeError(err, 'TE:202', 'number');

// Returns false.
TypeError.isTypeError(err, 'TE:202', 'string');

// Returns false.
TypeError.isTypeError(new Array());
```


# Overview

The \`TypeErrors\` object

## `TypeErrors {}`

The `TypeErrors` is an extension of the [`CommonErrors`](/draft-5/commonerrors/overview) object that represents multiple identification numbers under which the errors of the [`TypeError`](/draft-5/typeerror/overview) type are prepared to throw.

{% embed url="<https://github.com/angular-package/error/blob/main/src/lib/type-errors.class.ts>" %}
`type-errors.class.ts`
{% endembed %}

### Methods

|                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| <p><strong>public</strong> <a href="/pages/RVqwheMXmibQ0XyKkwZs"><strong>get()</strong></a>: <mark style="color:green;">TypeError</mark><<mark style="color:green;">ErrorId</mark>>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    | <mark style="color:green;">undefined</mark><br>Returns the <a href="/pages/wXU3s9b3bJiG5x5vWa8P"><code>TypeError</code></a> instance of the given <a href="/pages/6Nle1uMltWSb2uh6hgTQ#unique-identification">unique identification</a> <a href="/pages/RVqwheMXmibQ0XyKkwZs#id-errorid"><code>id</code></a> if set, otherwise <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined"><code>undefined</code></a>.</p> |
| <p><strong>public</strong> <a href="/pages/qEGnjIF9YwPQ1ZJO3qK6"><strong>getErrors()</strong></a>: { \[<mark style="color:green;">Key</mark> in <mark style="color:green;">Id</mark>]: <mark style="color:green;">RangeError</mark><<mark style="color:green;">Key</mark>>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             | <mark style="color:green;">undefined</mark> }<br>Returns an <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object"><code>object</code></a> of set type errors, where the key is a <a href="/pages/6Nle1uMltWSb2uh6hgTQ#unique-identification">unique identification</a>.</p>                                                                                                                                             |
| <p><strong>public</strong> <a href="/pages/tPGpxe2ljDxrbFB5Te4M"><strong>set()</strong></a><strong>:</strong> <mark style="color:green;">this</mark><br>Sets the <a href="/pages/wXU3s9b3bJiG5x5vWa8P"><code>TypeError</code></a> object with the message built from the given required <a href="/pages/jOiEQyLS4CUvWue1cy3s#problem-string"><code>problem</code></a>, <a href="/pages/jOiEQyLS4CUvWue1cy3s#fix-string"><code>fix</code></a>, <a href="/pages/jOiEQyLS4CUvWue1cy3s#id-errorid"><code>id</code></a>, and optional <a href="/pages/jOiEQyLS4CUvWue1cy3s#type-string"><code>type</code></a> on the given or stored <a href="/pages/jOiEQyLS4CUvWue1cy3s#template-typeerrors.template"><code>template</code></a> under the given <a href="/pages/jOiEQyLS4CUvWue1cy3s#id-errorid"><code>id</code></a>.</p> |                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |


# Generic type variables

The \`TypeErrors\` object generic type variables

## `TypeErrors<`<mark style="color:green;background-color:green;">`Id`</mark>`>`

#### <mark style="color:green;">`Id`</mark>`extends`[<mark style="color:green;">`string`</mark>](https://www.typescriptlang.org/docs/handbook/basic-types.html#string)

​A generic type variable constrained by the [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String), by default of the value **captured** from the provided [rest parameter](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/rest_parameters) [`id`](https://error.angular-package.dev/draft-5/typeerrors/pages/xjPZ5nFQyIiPqVeISurh#...id-id) indicates the identification type of a new [`TypeErrors`](/draft-5/typeerrors/overview) instance.

{% code title="type-errors.class.ts" %}

```typescript
class TypeErrors<
  Id extends string // <--- Declare generic type variable Id.
> extends CommonErrors<Id> {
  constructor(
    ...id: Id[] // <--- Capture generic type variable Id.
  ) {
    super(...id);
  }
}
```

{% endcode %}


# Constructor

The \`TypeErrors\` constructor

## `TypeErrors()`

Creates the [`TypeErrors`](/draft-5/typeerrors/overview) instance of [unique identification](/draft-5/getting-started/basic-concepts#unique-identification) numbers under which the [`TypeError`](/draft-5/typeerror/overview) objects are stored.

{% code title="type-errors.class.ts" %}

```typescript
constructor(...id: Id[]) {
  super(...id);
}
```

{% endcode %}

### Parameters

#### `...id:`[<mark style="color:green;">`Id`</mark>](/draft-5/typeerrors/generic-type-variables#typeerrors-less-than-id-greater-than)`[]`

A [rest parameter](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/rest_parameters) of generic type variable [`Id`](/draft-5/typeerrors/generic-type-variables#typeerrors-less-than-id-greater-than) indicates [unique identification](/draft-5/getting-started/basic-concepts#unique-identification) numbers under which the [`TypeError`](/draft-5/typeerror/overview) objects are stored.

## Example usage

```typescript
// Example usage.
import { TypeErrors } from '@angular-package/error';

// Returns TypeErrors {}
new TypeErrors('RE: 4332', 'RE: 4331', 'RE: 4330');

// Returns TypeErrors {}
new TypeErrors('RV: 332', 'RV: 331', 'RV: 330');
```


# Methods

The \`TypeErrors\` object methods

|                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| <p><strong>public</strong> <a href="/pages/RVqwheMXmibQ0XyKkwZs"><strong>get()</strong></a>: <mark style="color:green;">TypeError</mark><<mark style="color:green;">ErrorId</mark>>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    | <mark style="color:green;">undefined</mark><br>Returns the <a href="/pages/wXU3s9b3bJiG5x5vWa8P"><code>TypeError</code></a> instance of the given <a href="/pages/6Nle1uMltWSb2uh6hgTQ#unique-identification">unique identification</a> <a href="/pages/RVqwheMXmibQ0XyKkwZs#id-errorid"><code>id</code></a> if set, otherwise <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined"><code>undefined</code></a>.</p> |
| <p><strong>public</strong> <a href="/pages/qEGnjIF9YwPQ1ZJO3qK6"><strong>getErrors()</strong></a>: { \[<mark style="color:green;">Key</mark> in <mark style="color:green;">Id</mark>]: <mark style="color:green;">TypeError</mark><<mark style="color:green;">Key</mark>>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              | <mark style="color:green;">undefined</mark> }<br>Returns an <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object"><code>object</code></a> of set type errors, where the key is a <a href="/pages/6Nle1uMltWSb2uh6hgTQ#unique-identification">unique identification</a>.</p>                                                                                                                                             |
| <p><strong>public</strong> <a href="/pages/tPGpxe2ljDxrbFB5Te4M"><strong>set()</strong></a><strong>:</strong> <mark style="color:green;">this</mark><br>Sets the <a href="/pages/wXU3s9b3bJiG5x5vWa8P"><code>TypeError</code></a> object with the message built from the given required <a href="/pages/jOiEQyLS4CUvWue1cy3s#problem-string"><code>problem</code></a>, <a href="/pages/jOiEQyLS4CUvWue1cy3s#fix-string"><code>fix</code></a>, <a href="/pages/jOiEQyLS4CUvWue1cy3s#id-errorid"><code>id</code></a>, and optional <a href="/pages/jOiEQyLS4CUvWue1cy3s#type-string"><code>type</code></a> on the given or stored <a href="/pages/jOiEQyLS4CUvWue1cy3s#template-typeerrors.template"><code>template</code></a> under the given <a href="/pages/jOiEQyLS4CUvWue1cy3s#id-errorid"><code>id</code></a>.</p> |                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |


# get()

Returns the \`TypeError\` instance of the given unique identification

## `TypeErrors.prototype.get()`

Returns the [`TypeError`](/draft-5/typeerror/overview) instance of the given [unique identification](/draft-5/getting-started/basic-concepts#unique-identification) [`id`](#id-errorid) if set, otherwise [`undefined`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined).

{% code title="type-errors.class.ts" %}

```typescript
public get<ErrorId extends Id>(id: ErrorId): TypeError<ErrorId> | undefined {
  return this.errors.get(id);
}
```

{% endcode %}

### Generic type variables

#### <mark style="color:green;">`ErrorId`</mark>`extends`[<mark style="color:green;">`Id`</mark>](/draft-5/rangeerrors/generic-type-variables#rangeerrors-less-than-id-greater-than)

A generic type variable `ErrorId` constrained by the generic type variable [`Id`](/draft-5/rangeerrors/generic-type-variables#rangeerrors-less-than-id-greater-than) of the [`Errors`](/draft-5/errors/overview) object indicates the type picked from the [`Id`](/draft-5/rangeerrors/generic-type-variables#rangeerrors-less-than-id-greater-than) and its exact type is useful in picking the specific range error from the storage.

### Parameters

#### `id:`[<mark style="color:green;">`ErrorId`</mark>](#erroridextendsid)

The [unique identification](/draft-5/getting-started/basic-concepts#unique-identification) number of generic type variable [`ErrorId`](#erroridextendsid) to pick an error from the object.

### Return type

#### `TypeError<`[<mark style="color:green;">`ErrorId`</mark>](#erroridextendsid)`> |`[<mark style="color:green;">`undefined`</mark>](https://www.typescriptlang.org/docs/handbook/basic-types.html#null-and-undefined)

The **return type** is the [`TypeError`](/draft-5/typeerror/overview) object that takes the generic type variable [`ErrorId`](#erroridextendsid) or [`undefined`](https://www.typescriptlang.org/docs/handbook/basic-types.html#null-and-undefined).

### Returns

The **return value** is the [`TypeError`](/draft-5/typeerror/overview) instance of the given [`id`](#id-errorid) if set, otherwise [`undefined`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined).

## Example usage

```typescript
// Example usage.
import { TypeErrors } from '@angular-package/error';

// Define type errors.
const typeErrors = new TypeErrors('(TE: 4332)', '(TE: 4331)', '(TE: 4330)');

// Set the `TypeError` objects under the given identification numbers.
typeErrors
  .set(
    'Age is 99',
    'Age must be',
    '(TE: 4330)',
    'string',
  )
  .set('Detected numbers', 'Provide only letters', '(TE: 4331)', 'number');

/*
  Returns TypeError: Problem(TE: 4330): Age is 99 => Fix: Age must be must be of the string
  of type
  TypeError<"(TE: 4330)", undefined> | undefined
*/
typeErrors.get('(TE: 4330)');

// Returns undefined of type TypeError<"(TE: 4332)", undefined> | undefined
typeErrors.get('(TE: 4332)');
```




---

[Next Page](/llms-full.txt/1)

