> For the complete documentation index, see [llms.txt](https://error.angular-package.dev/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://error.angular-package.dev/error/methods/static-define.md).

# static define()

## `Error.define()`

Defines the [`Error`](/error/overview.md) instance with the [message](/commonerror/accessors/get-message.md) built of the given required [`problem`](#problem-string), [`fix`](#fix-string) and optional [`id`](#id-id) on the given or stored [`template`](#template-error.template).

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

```typescript
public static define<Id extends string>(
  problem: string,
  fix: string,
  id?: Id,
  template = Error.template
): Error<Id> {
  return new this(problem, fix, id, template);
}
```

{% endcode %}

### Generic type variables

#### <mark style="color:green;">`Id`</mark>`extends`[<mark style="color:green;">`string`</mark>](https://www.typescriptlang.org/docs/handbook/basic-types.html#string)

A generic type variable constrained by the [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String), by default of the value **captured** from the provided optional [`id`](#id-id) indicates the [identification](/getting-started/basic-concepts.md#identification) type of a new [`Error`](/error/overview.md) instance.

### 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](/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>](#idextendsstring)

Optional unique [identification](/getting-started/basic-concepts.md#identification) to the given [`problem`](#problem-string) of generic type variable [`Id`](#idextendsstring).

#### `template =`<mark style="color:green;">`Error`</mark>`.template`

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

### Return type

#### `Error<`[<mark style="color:green;">`Id`</mark>](#idextendsstring)`>`

The **return type** is the [`Error`](/error/overview.md) object that takes generic type variable [`Id`](#idextendsstring).

### Returns

The **return value** is a new instance of the [`Error`](/error/overview.md) with the [message](/commonerror/accessors/get-message.md) built from the given required [`problem`](#problem-string), [`fix`](#fix-string) and optional [`id`](#id-id) on the [`template`](#template-error.template).

## Example usage

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

// Returns "Error: ProblemTE:201: Wrong type => Fix: Change the type".
Error.define('Wrong type', 'Change the type', 'TE:201');
```
