# static define()

## `TypeError.define()`

Defines the [`TypeError`](https://error.angular-package.dev/draft-5/typeerror) instance with the [message](https://error.angular-package.dev/draft-5/commonerror/accessors/get-message) built of the given required [`problem`](#problem-string), [`fix`](#fix-string) and optional [`id`](#id-id) and [`type`](#type-string) on the given or stored [`template`](#template-typeerror.template).

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

```typescript
public static define<
  Id extends string,
  Type extends string | undefined = undefined
>(
  problem: string,
  fix: string,
  id?: Id,
  type?: Type,
  template = TypeError.template
): TypeError<Id, Type> {
  return new this(problem, fix, id, type, 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/draft-5/getting-started/basic-concepts#identification) type of a new [`TypeError`](https://error.angular-package.dev/draft-5/typeerror) instance.

#### <mark style="color:green;">`Type`</mark>`extends`[<mark style="color:green;">`string`</mark>](https://www.typescriptlang.org/docs/handbook/basic-types.html#string)`|`[<mark style="color:green;">`undefined`</mark>](https://www.typescriptlang.org/docs/handbook/basic-types.html#null-and-undefined)`=`[<mark style="color:green;">`undefined`</mark>](https://www.typescriptlang.org/docs/handbook/basic-types.html#null-and-undefined)&#x20;

A generic type variable constrained by the [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) and [`undefined`](https://www.typescriptlang.org/docs/handbook/basic-types.html#null-and-undefined), by default of the value equal to [`undefined`](https://www.typescriptlang.org/docs/handbook/basic-types.html#null-and-undefined) indicates the captured type of the supplied [`type`](#type-type) of a new [`TypeError`](https://error.angular-package.dev/draft-5/typeerror) 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/draft-5/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/draft-5/getting-started/basic-concepts#identification) to the given [`problem`](#problem-string) of generic type variable [`Id`](#idextendsstring).

#### `type?:`[<mark style="color:green;">`Type`</mark>](#typeextendsstring-or-undefined-undefined)

The optional type of generic type variable [`Type`](#typeextendsstring-or-undefined-undefined) that causes an error to be thrown(or not thrown).

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

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

### Return type

#### `TypeError<`[<mark style="color:green;">`Id`</mark>](#idextendsstring)`,`[<mark style="color:green;">`Type`</mark>](#typeextendsstring-or-undefined-undefined)`>`

The **return type** is the [`TypeError`](https://error.angular-package.dev/draft-5/typeerror) object that takes generic type variable [`Id`](#idextendsstring) as identification and  generic type variable [`Type`](#typeextendsstring-or-undefined-undefined) as the type.

### Returns

The **return value** is a new instance of the [`TypeError`](https://error.angular-package.dev/draft-5/typeerror) with the [message](https://error.angular-package.dev/draft-5/commonerror/accessors/get-message) built from the given required [`problem`](#problem-string), [`fix`](#fix-string) and optional [`id`](#id-id), [`type`](#type-type) on the given or stored [`template`](#template-typeerror.template).

## Example usage

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

// Returns
// TypeError: Problem(TE:201): Wrong type => Fix: The parameter age type must be of the string
TypeError.define('Wrong type', 'The parameter age type', '(TE:201)', 'string');
```
