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