# static isTypeError()

## `TypeError.isTypeError()`

Checks whether the [`value`](#value-any) of [`any`](https://www.typescriptlang.org/docs/handbook/basic-types.html#any) type is an instance of [`TypeError`](https://error.angular-package.dev/draft-5/typeerror) of any or the given [`type`](#type-type) and [identification](#id-id).

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

```typescript
public static isTypeError<
  Id extends string,
  Type extends string | undefined = undefined
>(value: any, id?: Id, type?: Type): value is TypeError<Id, Type> {
  return (
    super.isError(value, id) &&
    (typeof type === 'string' ? (value as any).type === type : true)
  );
}
```

{% 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 the [`TypeError`](https://error.angular-package.dev/draft-5/typeerror) via [return type](#return-type).

#### <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) via [return type](#return-type).

### Parameters

#### `value:`[<mark style="color:green;">`any`</mark>](https://www.typescriptlang.org/docs/handbook/basic-types.html#any)

The value of [`any`](https://www.typescriptlang.org/docs/handbook/basic-types.html#any) type to check against the [`TypeError`](https://error.angular-package.dev/draft-5/typeerror) instance.

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

Optional unique [identification](https://error.angular-package.dev/draft-5/getting-started/basic-concepts#identification) of generic type variable [`Id`](#idextendsstring) to check whether the given [`value`](#value-any) contains.

#### `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) to check whether the given [`value`](#value-any) contains.

### Return type

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

The **return type** is a [`boolean`](https://www.typescriptlang.org/docs/handbook/basic-types.html#boolean) resulting from its statement indicating the [`value`](#value-any) is the [`TypeError`](https://error.angular-package.dev/draft-5/typeerror) object that takes the 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 [`boolean`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean) type indicating whether the given [`value`](#value-any) is an instance of [`TypeError`](https://error.angular-package.dev/draft-5/typeerror) of any or the given optional [`type`](#type-type) and [`id`](#id-id) properties.

## Example usage

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

// Define error.
const err = TypeError.define('Wrong type', 'Change the type', 'TE:201', 'string');

// Returns true.
TypeError.isTypeError(err);

// Returns true.
TypeError.isTypeError(err, 'TE:201');

// Returns true.
TypeError.isTypeError(err, 'TE:201', 'string');

// Returns false.
TypeError.isTypeError(err, 'TE:202', 'number');

// Returns false.
TypeError.isTypeError(err, 'TE:202', 'string');

// Returns false.
TypeError.isTypeError(new Array());
```
