# static define()

## `RangeError.define()`

Defines the [`RangeError`](https://docs.angular-package.dev/error/rangeerror) instance with the [message](https://docs.angular-package.dev/error/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://docs.angular-package.dev/error/getting-started/basic-concepts#identification) type of a new [`RangeError`](https://docs.angular-package.dev/error/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://docs.angular-package.dev/error/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://docs.angular-package.dev/error/commonerror/properties/static-template#problem), [`{fix}`](https://docs.angular-package.dev/error/commonerror/properties/static-template#fix) and optional [`{id}`](https://docs.angular-package.dev/error/commonerror/properties/static-template#id), [`{max}`](https://docs.angular-package.dev/error/commonerror/properties/static-template#max), [`{min}`](https://docs.angular-package.dev/error/commonerror/properties/static-template#min) tags. By default, the value is equal to the static property [`RangeError.template`](https://docs.angular-package.dev/error/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://docs.angular-package.dev/error/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://docs.angular-package.dev/error/rangeerror) with the [message](https://docs.angular-package.dev/error/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);
```


---

# 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://docs.angular-package.dev/error/rangeerror/methods/static-define.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.
