Skip to content

fix: registerDecorator askes for ValidatorOptions instead of ValidationOptions #302

Closed

Description

@baocancode

Hi,

In the example of custom validation decorator https://github.com/typestack/class-validator#custom-validation-decorators I can see a options object with type ValidationOptions is passed to registerDecorator:

export function IsLongerThan(property: string, validationOptions?: ValidationOptions) {
   return function (object: Object, propertyName: string) {
        registerDecorator({
            name: "isLongerThan",
            target: object.constructor,
            propertyName: propertyName,
            constraints: [property],
            options: validationOptions,
...

But in https://github.com/typestack/class-validator/blob/master/src/register-decorator.ts, the options field is of type ValidatorOptions (line 36).

options?: ValidatorOptions;

Is that a mistake? Sorry if this has been asked before.

Activity

  1. ngryman commented on Jan 30, 2019

    @ngryman

    I'm facing the same issue. As a consequence, I can't find a way to customize the error message as ValidatorOptions does not expose a message property.

  2. gc-o commented on Mar 21, 2019

    @gc-o

    I'm facing the same issue. As a consequence, I can't find a way to customize the error message as ValidatorOptions does not expose a message property.

    You can add a customized message by adding a defaultValue method on the class.

    
     defaultMessage() {
        return "$value is taken!";
      }
    
  3. AlysonBasilio commented on Apr 13, 2020

    @AlysonBasilio

    Any updates regarding this issue?

  4. vlapo commented on Apr 17, 2020

    @vlapo
    Contributor

    I think this is just a small typing issue. It should be ValidationOptions.

  5. added
    type: fix
    on Apr 17, 2020
  6. lock commented on Apr 25, 2020

    @lock

    This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

  7. locked as resolved and limited conversation to collaborators on Apr 25, 2020
  8. changed the title [-]registerDecorator askes for ValidatorOptions instead of ValidationOptions[/-] [+]fix: registerDecorator askes for ValidatorOptions instead of ValidationOptions[/+] on Aug 8, 2020
  9. added
    status: done/released
    on Aug 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: done/releasedtype: fix

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions