# static define()

## `Error.define()`

Defines the [`Error`](https://error.angular-package.dev/error) instance with the [message](https://error.angular-package.dev/commonerror/accessors/get-message) 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](https://error.angular-package.dev/getting-started/basic-concepts#identification) type of a new [`Error`](https://error.angular-package.dev/error) 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](https://error.angular-package.dev/getting-started/basic-concepts#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](https://error.angular-package.dev/getting-started/basic-concepts#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}`](https://error.angular-package.dev/commonerror/properties/static-template#problem), [`{fix}`](https://error.angular-package.dev/commonerror/properties/static-template#fix) and optional [`{id}`](https://error.angular-package.dev/commonerror/properties/static-template#id) tags. By default, the value is equal to the static property [`template`](https://error.angular-package.dev/commonerror/properties/static-template).

### Return type

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

The **return type** is the [`Error`](https://error.angular-package.dev/error) object that takes generic type variable [`Id`](#idextendsstring).

### Returns

The **return value** is a new instance of the [`Error`](https://error.angular-package.dev/error) with the [message](https://error.angular-package.dev/commonerror/accessors/get-message) 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');
```


---

# 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/error/methods/static-define.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.
