getErrors()

Returns the object of set validation errors

ValidationErrors.prototype.getErrors()

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

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

Return type

{ [KeyinId]:ValidationError<Id> }

The return type is an object of the ValidationError objects in the keys of generic type variable Id.

Returns

The return value is an object of set errors.

Example usage

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

// Define validation errors.
const validationErrors = new ValidationErrors(
  '(VE: 4332)',
  '(VE: 4331)',
  '(VE: 4330)'
);

// Set the `ValidationError` objects under the given identification numbers.
validationErrors
  .set('Age is 99', 'Age must be', '(VE: 4330)')
  .set('Detected numbers', 'Provide only letters', '(VE: 4331)');

/*
  Returns:
  {
    (VE: 4330): ...,
    (VE: 4331): ...
  }
  of type
  {
    "(VE: 4332)": ValidationError<"(VE: 4332)"> | undefined;
    "(VE: 4331)": ValidationError<"(VE: 4331)"> | undefined;
    "(VE: 4330)": ValidationError<"(VE: 4330)"> | undefined;
  }
*/
validationErrors.getErrors();

Last updated