getErrors()

The method returns the object of set errors

Errors.prototype.getErrors()

Returns an object of set errors, where the key is a unique identification.

errors.class.ts
public getErrors(): { [Key in Id]: Error<Key> | undefined } {
  return Object.fromEntries(this.errors.entries()) as any;
}

Return type

{ [KeyinId]: Error<Key> |undefined }

A return type is an object of the Error objects or undefined in the keys of generic type variable Id.

Returns

The return value is an object of set errors.

Example usage

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

// Define general errors.
const generalErrors = new Errors('EG: 4332', 'EG: 4331', 'EG: 4330');

// Set the `Error` objects under the given identification numbers.
generalErrors
  .set(
    'Bad parameter type, detected number',
    'Provide proper type, the `string`',
    'EG: 4330'
  )
  .set('Detected numbers', 'Provide only letters', 'EG: 4331');

// Returns:
/*
Returns
  {
    EG: 4330: ...,
    EG: 4331: ...
  }
  of type
  {
    "EG: 4332": Error<"EG: 4332">;
    "EG: 4331": Error<"EG: 4331">;
    "EG: 4330": Error<"EG: 4330">;
  }
*/
generalErrors.getErrors();

Last updated