★ Constructor

The `TypeError` object constructor

TypeError()

Creates a TypeError instance that represents type error with the message built of the given described problem and its solution, optional type, and an explicit identification on the supplied or stored error message template.

type-error.class.ts
constructor(
  problem: string,
  fix: string,
  id?: Id,
  type?: Type,
  template = TypeError.template
) {
  super(problem, fix, id, template, { type });
  this.#type = type;
}

Parameters

problem:string

Description of the problem of a string type.

fix:string

A solution to the given problem of a string type.

id?:Id

Optional unique identification to the given problem of generic type variable Id.

type?:Type

The optional type of generic type variable Type that causes an error to be thrown(or not thrown).

template:string=TypeError.template

Optional template of the error message of string type with the replaceable {problem}, {fix} and optional {id}, {type} tags. By default, the value is equal to the static property TypeError.template.

Example usage

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

// Returns
// TypeError: Problem(TE:201): Wrong type => Fix: The type of `age` parameter must be of the string
new TypeError('Wrong type', 'Change the type', '(TE:201)', 'string');

Last updated