Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: "[0]" must not be a sparse array item #234

Open
newerton opened this issue Feb 10, 2023 · 0 comments
Open

Error: "[0]" must not be a sparse array item #234

newerton opened this issue Feb 10, 2023 · 0 comments

Comments

@newerton
Copy link

D:\www\project\node_modules\joi\lib\errors.js:193
        return new exports.ValidationError(message, details, original);
               ^
ValidationError: [
  null
]

[1] "[0]" must not be a sparse array item
    at Object.exports.process (D:\www\project\node_modules\joi\lib\errors.js:193:16)
    at Object.internals.entry (D:\www\project\node_modules\joi\lib\validator.js:153:26)
    at Object.exports.entry (D:\www\project\node_modules\joi\lib\validator.js:27:30)
    at internals.Base.validate (D:\www\project\node_modules\joi\lib\base.js:548:26)
    at Object.internals.assert (D:\www\project\node_modules\joi\lib\index.js:225:27)
    at Object.assert (D:\www\project\node_modules\joi\lib\index.js:102:19)
    at Object.extend (D:\www\project\node_modules\joi\lib\index.js:156:14)
    at Object.<anonymous> (D:\www\project\src\app\register\validations\create-account.schema.validation.ts:8:21)
    at Module._compile (node:internal/modules/cjs/loader:1105:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)

Usage

import * as JoiBase from 'joi';
import phoneValidator from 'joi-phone-number';
const Joi = JoiBase.extend(phoneValidator);

export class CreateAccountSchemaValidation implements CreateSchema {
  createSchema(): JoiBase.ObjectSchema {
    return Joi.object({
      name: Joi.string()
        .min(5)
        .required()
        .label('Name')
        .messages(joiMessagesSchema),
      phone: Joi.string()
        .phoneNumber({ defaultCountry: 'BR', strict: true })
        .required()
        .label('Phone')
        .messages(joiMessagesSchema),
    });
  }
}

package.json

"@nestjs/core": "^9.3.8",
"joi": "^17.7.1",
"joi-phone-number": "^5.1.1",
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant