> For the complete documentation index, see [llms.txt](https://docs.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://docs.angular-package.dev/error/typeerror/methods/static-define.md).

# static define()

## `TypeError.define()`

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

### 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`](/error/typeerror/overview.md) 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`](/error/typeerror/overview.md) with the [message](/error/commonerror/accessors/get-message.md) 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');
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://docs.angular-package.dev/error/typeerror/methods/static-define.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
