Generic class validation
See original GitHub issueHello,
Is there any way to write validation on a generic class. Here an exemple of what I’d like to write :
export class ClassName<T> {
@IsNotEmpty()
@Expose()
@IsArray()
@ValidateNested({
each: true,
})
@Type(() => T)
public items: T[];
}
Do you have any idea ?
Thanks a lot for your answers 😃
Issue Analytics
- State:
- Created 5 years ago
- Reactions:14
- Comments:7 (1 by maintainers)
Top Results From Across the Web
TypeScript Generic with some validation | by Taufan - Medium
With generic, a single type can be reused with a variety of other types. Think of Promise , it can resolve to just...
Read more >Java generic type validation - Stack Overflow
First we have the generic class that accepts any type as T with an abstract method that ... NotNull; import javax.validation.constraints.
Read more >Generic data validation
Generic data can only be validated if it has a non-null DataType associated with it. When the DataType is null, the validation always...
Read more >GenericValidator (Oracle Communications Billing Care Java ...
com.oracle.communications.brm.cc.validation.model.impl.GenericValidator<T> ... Generic Validator is the parent class for all Validator classes.
Read more >Method Constraints with Bean Validation 2.0 - Baeldung
Cross-parameter constraints can be considered as the method validation equivalent to class-level constraints · Sometimes we'll need to validate ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Decorators are runtime artifact, hence why
Tdoesn’t exist.You should try create a class factory:
It might not compile, it’s just an idea that works in TypeGraphQL 😄 https://19majkel94.github.io/type-graphql/docs/interfaces-and-inheritance.html#resolvers-inheritance
I ran into this as well today and was able to solve it using mixins. It works well for my use case, but you need to create intermediate types to map the singletons returned by the class expression pattern. So it’s not really viable when you have multiple properties that differ based on generics.