Constructor
The `CommonError` object constructor
CommonError()
CommonError()Creates an error instance with the message built from the given problem, its solution, optional type, range, an explicit identification on the supplied or stored template.
constructor(
problem: string,
fix: string,
id?: Id,
template = CommonError.template,
additional?: { link?: string; max?: number; min?: number; type?: string }
) {
super(
CommonError.defineMessage`${problem}${fix}${id}${template}${additional}`
);
this.#fix = fix;
this.#id = id;
this.#link = additional?.link;
this.#problem = problem;
this.#template = template;
}Parameters
Description of the problem of a string type.
A solution to the given problem of a string type.
Optional unique identification to the given problem of generic type variable Id.
A template of error message with the replaceable {problem}, {fix} and optional {id}, {link}, {max}, {min} and {type} tags.
An optional object consists of optional link, min, max, and type properties to define the error message.
link - The link to read more about the thrown error replaceable on the given template as {link} tag.
max - The maximum number replaceable on the given template as {max} tag.
min - The minimum number is replaceable on the given template as {min} tag.
type - The type indicates the expected type that isn't throwing an error or the not expected type that is throwing an error replaceable on the given template as the {type} tag.
Example usage
Basic usage
Example with the given required problem and fix.
id
idExample with the given id.
id, template
id, templateExample with the given id and template.
id, template, additional{ min }
id, template, additional{ min }Example with the given id, template and property min of additional.
id, template, additional{ min, max }
id, template, additional{ min, max } Example with the given id, template and property min and max of additional.
id, template, additional{ min, max, type }
id, template, additional{ min, max, type } Example with the given id, template, property min, max and type of additional.
Last updated
Was this helpful?