# Generic type variables

## `TypeError<`<mark style="color:green;background-color:green;">`Id`</mark>`,Type>`

#### <mark style="color:green;">`Id`</mark>`extends`[<mark style="color:green;">`string`</mark>](https://www.typescriptlang.org/docs/handbook/basic-types.html#string)`=`[<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 [`id`](/typeerror/constructor.md#id-id) indicates the identification type of a new [`TypeError`](/typeerror/overview.md) instance.

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

```typescript
class TypeError<
  Id extends string,  // <--- Declare generic type variable Id.
  Type extends string | undefined = undefined
> extends Error {
  ...
  constructor(
    problem: string,
    fix: string,
    id?: Id, // <--- Capture generic type variable Id.
    type?: Type,
    template = TypeError.template
  ) { ... }
  ...
}
```

{% endcode %}

## `TypeError<Id,`<mark style="color:green;background-color:green;">`Type`</mark>`>`

#### <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)

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`](/typeerror/constructor.md#type-type) of a new [`TypeError`](/typeerror/overview.md) instance.

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

```typescript
class TypeError<
  Id extends string,
  Type extends string | undefined = undefined  // <--- Declare generic type variable Type.
> extends Error {
  ...
  constructor(
    problem: string,
    fix: string,
    id?: Id,
    type?: Type,  // <--- Capture generic type variable Type.
    template = TypeError.template
  ) { ... }
  ...
}
```

{% endcode %}


---

# 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/typeerror/generic-type-variables.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.
