website icon indicating copy to clipboard operation
website copied to clipboard

Fix code in `validations-and-constraints.md`

Open jthemphill opened this issue 1 year ago • 0 comments

Two kinds of errors here:

  1. Sequelize.STRING and Sequelize.INTEGER don't exist. These should be DataTypes.STRING and DataTypes.INTEGER instead.
  2. TypeScript assumes that this corresponds to the ModelValidateOptions that the validation method is defined in.

In a TypeScript file, we would write

User.init({
  // ...,
  validate: {
    customValidator(this: User, value: string | null) {
      // ...
    }
  }
})

But your examples are in JS, so I'm writing a JSDoc equivalent. While I wouldn't usually force types upon people who choose to write untyped code, this is a special case. Without this, the people who do choose to use types will otherwise see the wrong type here.

jthemphill avatar Mar 13 '25 23:03 jthemphill