# set()

## `ValidationErrors.prototype.set()`

Sets the [`ValidationError`](https://error.angular-package.dev/validationerror) 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-validationerrors.template) under the given [`id`](#id-errorid).

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

```typescript
public set<ErrorId extends Id>(
  problem: string,
  fix: string,
  id: ErrorId,
  template = ValidationErrors.template
): this {
  this.isAllowedId(id) &&
    this.errors.set(id, new ValidationError(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/rangeerrors/generic-type-variables#wrap-opening)

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

### Return type

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

## Example usage

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

// Define validation errors.
const validationErrors = new ValidationErrors(
  '(VE: 4332)',
  '(VE: 4331)',
  '(VE: 4330)'
);

// Set the `ValidationError` objects under the given identification numbers.
validationErrors
  .set('Age is 99', 'Age must be', '(VE: 4330)')
  .set('Detected numbers', 'Provide only letters', '(VE: 4331)');
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://error.angular-package.dev/validationerrors/methods/set.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
