question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Inheriting Validation decorators

See original GitHub issue

Description

From the docs:

If a property is redefined in the descendant class decorators will be applied on it both from that and the base class.

I’m not sure it works as it should.

Reproduction

import { MinLength, IsUppercase } from "class-validator";
import { validate } from "class-validator";

class BaseClass {
    @MinLength(10)
    someProperty: string;
}

class ChildClass extends BaseClass {
    @IsUppercase()
    someProperty: string;
}

const someObj = new ChildClass();
someObj.someProperty = 'HELLO';

validate(someObj).then(result => {
    console.log(result);
});

// the output is empty array []

From what I’m reading in docs, I thought @MinLength(10) is used alongside @IsUppercase(), but I don’t see it. Moreover, I’m not sure what empty array means.

Environment

  • nodejs: v12.17.0
  • typescript: 3.9.5

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:3
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
cduffcommented, Feb 9, 2021

Any update on this? I got hit by it again today. It’s quite confusing at the moment as some decorators are inherited (e.g. @IsOptional) and others aren’t.

3reactions
NickKelly1commented, Sep 8, 2020

There is now a PR for this

Read more comments on GitHub >

github_iconTop Results From Across the Web

How can I make my class decorator only run on the outermost ...
I'm using class-validator decorators to validate data classes that involve data coming from outside of my application at runtime.
Read more >
Validation decorator - pydantic
The validate_arguments decorator allows the arguments passed to a function to be parsed and validated using the function's annotations before the function is ......
Read more >
Validation - Next.js API Decorators
The options you can pass into ValidationPipe are inherited from class-validator with an additional transformerOptions property, which inherits class-transformer ...
Read more >
Validation | NestJS - A progressive Node.js framework
In addition to these, all class-validator options (inherited from the ... (returned) object of any properties that do not use any validation decorators....
Read more >
How to Validate Your Data with Custom Validators of Pydantic ...
To create a custom validator, we need to import the validator function which works like a decorator and decorates some methods of the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found