Skip to content

Commit

Permalink
fix(types): fix ValidationErrorItem types (#13108)
Browse files Browse the repository at this point in the history
Co-authored-by: papb <papb1996@gmail.com>
  • Loading branch information
LorhanSohaky and papb committed Mar 21, 2021
1 parent 466e361 commit e35a9bf
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 26 deletions.
34 changes: 17 additions & 17 deletions lib/errors/validation-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,18 @@ class ValidationError extends BaseError {
*/
class ValidationErrorItem {
/**
* Creates new validation error item
* Creates a new ValidationError item. Instances of this class are included in the `ValidationError.errors` property.
*
* @param {string} message An error message
* @param {string} type The type/origin of the validation error
* @param {string} path The field that triggered the validation error
* @param {string} value The value that generated the error
* @param {object} [inst] the DAO instance that caused the validation error
* @param {object} [validatorKey] a validation "key", used for identification
* @param {string} [message] An error message
* @param {string} [type] The type/origin of the validation error
* @param {string} [path] The field that triggered the validation error
* @param {string} [value] The value that generated the error
* @param {Model} [instance] the DAO instance that caused the validation error
* @param {string} [validatorKey] a validation "key", used for identification
* @param {string} [fnName] property name of the BUILT-IN validator function that caused the validation error (e.g. "in" or "len"), if applicable
* @param {string} [fnArgs] parameters used with the BUILT-IN validator function, if applicable
* @param {Array} [fnArgs] parameters used with the BUILT-IN validator function, if applicable
*/
constructor(message, type, path, value, inst, validatorKey, fnName, fnArgs) {
constructor(message, type, path, value, instance, validatorKey, fnName, fnArgs) {
/**
* An error message
*
Expand All @@ -77,21 +77,21 @@ class ValidationErrorItem {
/**
* The type/origin of the validation error
*
* @type {string}
* @type {string | null}
*/
this.type = null;

/**
* The field that triggered the validation error
*
* @type {string}
* @type {string | null}
*/
this.path = path || null;

/**
* The value that generated the error
*
* @type {string}
* @type {string | null}
*/
this.value = value !== undefined ? value : null;

Expand All @@ -100,28 +100,28 @@ class ValidationErrorItem {
/**
* The DAO instance that caused the validation error
*
* @type {Model}
* @type {Model | null}
*/
this.instance = inst || null;
this.instance = instance || null;

/**
* A validation "key", used for identification
*
* @type {string}
* @type {string | null}
*/
this.validatorKey = validatorKey || null;

/**
* Property name of the BUILT-IN validator function that caused the validation error (e.g. "in" or "len"), if applicable
*
* @type {string}
* @type {string | null}
*/
this.validatorName = fnName || null;

/**
* Parameters used with the BUILT-IN validator function, if applicable
*
* @type {string}
* @type {Array}
*/
this.validatorArgs = fnArgs || [];

Expand Down
44 changes: 35 additions & 9 deletions types/lib/errors.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import Model from "./model";

/**
* The Base Error all Sequelize Errors inherit from.
*/
Expand Down Expand Up @@ -33,29 +35,53 @@ export class ValidationError extends BaseError {

export class ValidationErrorItem {
/** An error message */
public readonly message: string;
public readonly message: string;

/** The type of the validation error */
public readonly type: string;
/** The type/origin of the validation error */
public readonly type: string | null;

/** The field that triggered the validation error */
public readonly path: string;
public readonly path: string | null;

/** The value that generated the error */
public readonly value: string;
public readonly value: string | null;

/** The DAO instance that caused the validation error */
public readonly instance: Model | null;

/** A validation "key", used for identification */
public readonly validatorKey: string | null;

/** Property name of the BUILT-IN validator function that caused the validation error (e.g. "in" or "len"), if applicable */
public readonly validatorName: string | null;

/** Parameters used with the BUILT-IN validator function, if applicable */
public readonly validatorArgs: unknown[];

public readonly original: Error;

/**
* Validation Error Item
* Instances of this class are included in the `ValidationError.errors` property.
* Creates a new ValidationError item. Instances of this class are included in the `ValidationError.errors` property.
*
* @param message An error message
* @param type The type of the validation error
* @param type The type/origin of the validation error
* @param path The field that triggered the validation error
* @param value The value that generated the error
* @param instance the DAO instance that caused the validation error
* @param validatorKey a validation "key", used for identification
* @param fnName property name of the BUILT-IN validator function that caused the validation error (e.g. "in" or "len"), if applicable
* @param fnArgs parameters used with the BUILT-IN validator function, if applicable
*/
constructor(message?: string, type?: string, path?: string, value?: string);
constructor(
message?: string,
type?: string,
path?: string,
value?: string,
instance?: object,
validatorKey?: string,
fnName?: string,
fnArgs?: unknown[]
);
}

export interface CommonErrorProperties {
Expand Down

0 comments on commit e35a9bf

Please sign in to comment.