# set()

## `TypeErrors.prototype.set()`

Sets the [`TypeError`](https://docs.angular-package.dev/error/typeerror) object with the message built from the given required [`problem`](#problem-string), [`fix`](#fix-string), [`id`](#id-errorid) and optional [`type`](#type-string) on the given or stored [`template`](#template-typeerrors.template) under the given [`id`](#id-errorid).

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

```typescript
public set<ErrorId extends Id>(
  problem: string,
  fix: string,
  id: ErrorId,
  type?: string,
  template = TypeErrors.template
): this {
  this.isAllowedId(id) &&
    this.errors.set(id, new TypeError(problem, fix, id, type, 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#typeerrors-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#typeerrors-less-than-id-greater-than) of the [`TypeErrors`](https://docs.angular-package.dev/error/typeerrors) object indicates the type picked from the [`Id`](https://docs.angular-package.dev/error/generic-type-variables#typeerrors-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).

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

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

#### `template =`<mark style="color:green;">`TypeErrors`</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 [`{type}`](https://docs.angular-package.dev/error/commonerror/properties/static-template#type) tags. By default, the value is equal to the static property `TypeErrors.template`.

### Return type

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

## Example usage

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

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

// Set the `TypeErrors` objects under the given identification numbers.
typeErrors
  .set(
    'Age is 99 string type',
    'Age must be',
    '(TE: 4330)',
    'number'
  )
  .set('Detected numbers', 'Provide only letters', '(TE: 4330)');
```
