# ★ Constructor

## `TypeError()`

Creates a [`TypeError`](https://docs.angular-package.dev/error/typeerror) instance that represents type error with the [message](https://docs.angular-package.dev/error/commonerror/accessors/get-message) built of the given described [problem](#problem-string) and its [solution](#fix-string), optional [type](#type-type), and an explicit [identification](#id-id) on the supplied or stored error message [template](#template-string-typeerror.template).

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

```typescript
constructor(
  problem: string,
  fix: string,
  id?: Id,
  type?: Type,
  template = TypeError.template
) {
  super(problem, fix, id, template, { type });
  this.#type = type;
}
```

{% 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](https://docs.angular-package.dev/error/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>](https://docs.angular-package.dev/error/generic-type-variables#wrap-opening)

Optional unique [identification](https://docs.angular-package.dev/error/getting-started/basic-concepts#identification) to the given [`problem`](#problem-string) of generic type variable [`Id`](https://docs.angular-package.dev/error/generic-type-variables#typeerror-less-than-id-type-greater-than).

#### `type?:`[<mark style="color:green;">`Type`</mark>](https://docs.angular-package.dev/error/generic-type-variables#wrap-opening-1)

The optional type of generic type variable [`Type`](https://docs.angular-package.dev/error/generic-type-variables#typeerror-less-than-id-type-greater-than-1) that causes an error to be thrown(or not thrown).

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

Optional template of the error message of [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) type with the replaceable [`{problem}`](https://docs.angular-package.dev/error/commonerror/properties/static-template#problem), [`{fix}`](https://docs.angular-package.dev/error/commonerror/properties/static-template#fix) and optional [`{id}`](https://docs.angular-package.dev/error/commonerror/properties/static-template#id), [`{type}`](https://docs.angular-package.dev/error/commonerror/properties/static-template#type) tags. By default, the value is equal to the static property [`TypeError.template`](https://docs.angular-package.dev/error/typeerror/properties/static-template).

## Example usage

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

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