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

fix: registerDecorator askes for ValidatorOptions instead of ValidationOptions #302

Closed
baocancode opened this issue Dec 28, 2018 · 5 comments
Labels
status: done/released Issue has been completed, no further action is needed. type: fix Issues describing a broken feature.

Comments

@baocancode
Copy link

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.

@ngryman
Copy link

ngryman commented Jan 30, 2019

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.

@gc-o
Copy link

gc-o commented Mar 21, 2019

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!";
  }

@AlysonBasilio
Copy link

Any updates regarding this issue?

@vlapo
Copy link
Contributor

vlapo commented Apr 17, 2020

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

@vlapo vlapo added the type: fix Issues describing a broken feature. label Apr 17, 2020
@vlapo vlapo closed this as completed in 7909ec6 Apr 18, 2020
@lock
Copy link

lock bot commented Apr 25, 2020

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.

@lock lock bot locked as resolved and limited conversation to collaborators Apr 25, 2020
@NoNameProvided NoNameProvided changed the title registerDecorator askes for ValidatorOptions instead of ValidationOptions fix: registerDecorator askes for ValidatorOptions instead of ValidationOptions Aug 8, 2020
@NoNameProvided NoNameProvided added the status: done/released Issue has been completed, no further action is needed. label Aug 8, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
status: done/released Issue has been completed, no further action is needed. type: fix Issues describing a broken feature.
Development

No branches or pull requests

6 participants