# ★ Constructor

## `ValidationError()`

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

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

```typescript
constructor(
  problem: string,
  fix: string,
  id?: Id,
  template = ValidationError.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.md#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/validationerror/generic-type-variables.md#validationerror-less-than-id-greater-than)

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

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

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

## Example usage

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

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


---

# 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/draft-5/validationerror/constructor.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.
