# static define()

## `RangeError.define()`

Defines the [`RangeError`](https://error.angular-package.dev/draft-5/rangeerror) instance with the [message](https://error.angular-package.dev/draft-5/commonerror/accessors/get-message) built from the given required [`problem`](#problem-string), [`fix`](#fix-string) and optional [`id`](#id-id), [`max`](#max-max), [`min`](#min-min) on the given or stored [`template`](#template-rangeerror.template).

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

```typescript
public static define<
  Id extends string,
  Min extends number | undefined = undefined,
  Max extends number | undefined = undefined
>(
  problem: string,
  fix: string,
  id?: Id,
  min?: Min,
  max?: Max,
  template = RangeError.template
): RangeError<Id, Min, Max> {
  return new this(problem, fix, id, min, max, 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](https://error.angular-package.dev/draft-5/getting-started/basic-concepts#identification) type of a new [`RangeError`](https://error.angular-package.dev/draft-5/rangeerror) instance.

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

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

Description of the [problem](#problem-string) 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](https://error.angular-package.dev/draft-5/getting-started/basic-concepts#identification) to the given [`problem`](#problem-string) of generic type variable [`Id`](#idextendsstring).

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

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

The optional maximum range of generic type variable [`Max`](#maxextendsnumber-or-undefined-undefined) that causes an error to be thrown(or not thrown).

#### `template =`<mark style="color:green;">`RangeError`</mark>`.template`

A template of error message with the replaceable [`{problem}`](https://error.angular-package.dev/draft-5/commonerror/properties/static-template#problem), [`{fix}`](https://error.angular-package.dev/draft-5/commonerror/properties/static-template#fix) and optional [`{id}`](https://error.angular-package.dev/draft-5/commonerror/properties/static-template#id), [`{max}`](https://error.angular-package.dev/draft-5/commonerror/properties/static-template#max), [`{min}`](https://error.angular-package.dev/draft-5/commonerror/properties/static-template#min) tags. By default, the value is equal to the static property [`RangeError.template`](https://error.angular-package.dev/draft-5/rangeerror/properties/static-template).

### Return type

#### `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 the [`RangeError`](https://error.angular-package.dev/draft-5/rangeerror) object that takes 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 new instance of the [`RangeError`](https://error.angular-package.dev/draft-5/rangeerror) with the [message](https://error.angular-package.dev/draft-5/commonerror/accessors/get-message) built from the given required [`problem`](#problem-string), [`fix`](#fix-string) and optional [`id`](#id-id), [`min`](#min-min), [`max`](#max-max) on the given or stored [`template`](#template-rangeerror.template).

## Example usage

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

// Returns
// RangeError: ProblemTE:201: Wrong age => Fix: The value must be between 9 and 27
RangeError.define('Wrong age', 'The value must be', 'TE:201', 9, 27);
```
