Closed alvipeo closed 2 years ago
Hey alvipeo!
Yea there are limits to what I try to detect. I don't check if a type is aliased to a primitive type. It isn't a common use case in the apps i've written at least. anyone doing that can just disable the rule for that property.
For your releases status list - I DO require a type property for arrays. The only non-primitive type that I don't require a @Type() for is enums.
So you could fix your issue there a couple of ways
method 1: Disable the rule
// eslint-disable-next-line @darraghor/nestjs-typed/validated-non-primitive-property-needs-type-decorator
@ApiProperty({
enum: ["planned", "failed", "blocked", "in-progress"]
})
@IsIn(RELEASE_STATUSES)
status!: ReleaseStatus;
Method 2: indicate the array element type
@ApiProperty({
enum: ["planned", "failed", "blocked", "in-progress"]
})
@IsIn(RELEASE_STATUSES)
@Type(()=> String)
status!: ReleaseStatus;
Method 3: Use an enum (This is what I usually do for these)
export enum ReleaseStatus {
PLANNED="planned";
FAILED= "failed";
BLOCKED= "blocked"
IN_PROGRESS = "in-progress"
}
@ApiProperty({
enum: ReleaseStatus,
enumName "ReleaseStatus"
})
@IsEnum(ReleaseStatus)
status!: ReleaseStatus;
Here's a property of some union type with a validation decorator:
and the
ReleaseStatus
defined as follows:When I run lint I get:
I'm not sure if I'm wrong somewhere or the rule doesn't work here...
Another variant is with a simple type aliasing:
This produces same error.