# static isRangeError()

## `RangeError.isRangeError()`

Checks whether the [`value`](#value-any) of [`any`](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#any) type is an instance of [`RangeError`](https://error.angular-package.dev/draft-5/rangeerror) of any or the given [minimum](#min-number)/[maximum](#max-number) range and [identification](#id-id).

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

```typescript
public static isRangeError<
  Id extends string,
  Min extends number | undefined = undefined,
  Max extends number | undefined = undefined
>(
  value: any,
  id?: Id,
  min?: Min,
  max?: Max
): value is RangeError<Id, Min, Max> {
  return (
    super.isError(value, id) &&
    (typeof min === 'number' ? (value as any).min === min : true) &&
    (typeof max === 'number' ? (value as any).max === max : 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 [`RangeError`](https://error.angular-package.dev/draft-5/rangeerror) via [return type](#return-type).

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

A generic type variable constrained by the [`number`](https://www.typescriptlang.org/docs/handbook/basic-types.html#number) 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 [`min`](#min-min) via the [return type](#return-type).

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

A generic type variable constrained by the [`number`](https://www.typescriptlang.org/docs/handbook/basic-types.html#number) 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 [`max`](#max-max) via the [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 [`RangeError`](https://error.angular-package.dev/draft-5/rangeerror) 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.

#### `min?:`[<mark style="color:green;">`Min`</mark>](#minextendsnumber-or-undefined-undefined)

The optional minimum range of generic type variable [`Min`](#minextendsnumber-or-undefined-undefined) that causes an error to be thrown(or not thrown) to check whether the given [`value`](#value-any) contains.

#### `max?:`[<mark style="color:green;">`Max`</mark>](#maxextendsnumber-or-undefined-undefined)

The optional minimum range of generic type variable [`Max`](#maxextendsnumber-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 RangeError<`[<mark style="color:green;">`Id`</mark>](#idextendsstring)`,`[<mark style="color:green;">`Min`</mark>](#minextendsnumber-or-undefined-undefined)`,`[<mark style="color:green;">`Max`</mark>](#maxextendsnumber-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 [`RangeError`](https://error.angular-package.dev/draft-5/rangeerror) object that takes the generic type variable [`Id`](#idextendsstring) as identification, [`Min`](#minextendsnumber-or-undefined-undefined) as minimum range and [`Max`](#maxextendsnumber-or-undefined-undefined) as maximum range.

### 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 [`RangeError`](https://error.angular-package.dev/draft-5/rangeerror) of any or the given optional [`min`](#min-min), [`max`](#max-max) and [`id`](#id-id) properties.

## Example usage

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

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

// Returns true.
RangeError.isRangeError(err);

// Returns true.
RangeError.isRangeError(err, 'TE:201');

// Returns false.
RangeError.isRangeError(err, 'TE:202', 9);

// Returns false.
RangeError.isRangeError(err, 'TE:202', 9, 27);

// Returns false.
RangeError.isRangeError(new Array());
```
