# set()

## `Errors.prototype.set()`

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

A generic type variable `ErrorId` constrained by the generic type variable [`Id`](https://error.angular-package.dev/generic-type-variables#errors-less-than-id-greater-than) of the [`Errors`](https://error.angular-package.dev/errors) object indicates the type picked from the [`Id`](https://error.angular-package.dev/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>](https://error.angular-package.dev/errors)`.template`

A template of error message with the replaceable [`{problem}`](https://error.angular-package.dev/commonerror/properties/static-template#problem), [`{fix}`](https://error.angular-package.dev/commonerror/properties/static-template#fix), [`{id}`](https://error.angular-package.dev/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');
```
