# set()

## `RangeErrors.prototype.set()`

Sets the [`RangeError`](https://docs.angular-package.dev/error/rangeerror) 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>](https://docs.angular-package.dev/error/generic-type-variables#rangeerrors-less-than-id-greater-than)

A generic type variable `ErrorId` constrained by the generic type variable [`Id`](https://docs.angular-package.dev/error/generic-type-variables#rangeerrors-less-than-id-greater-than) of the [`RangeErrors`](https://docs.angular-package.dev/error/rangeerrors) object indicates the type picked from the [`Id`](https://docs.angular-package.dev/error/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}`](https://docs.angular-package.dev/error/commonerror/properties/static-template#problem), [`{fix}`](https://docs.angular-package.dev/error/commonerror/properties/static-template#fix),[`{id}`](https://docs.angular-package.dev/error/commonerror/properties/static-template#id), and optional  [`{max}`](https://docs.angular-package.dev/error/commonerror/properties/static-template#max), [`{min}`](https://docs.angular-package.dev/error/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');
```
