darraghoriordan / eslint-plugin-nestjs-typed

Some eslint rules for working with NestJs projects
http://www.darraghoriordan.com
171 stars 34 forks source link

Type Decorator Required for optional array fields #22

Closed iddan-flycode closed 2 years ago

iddan-flycode commented 2 years ago

This code errors with the error: A non-primitve property with validation should probably use a @Type decorator

class ExampleDto {
  @ApiPropertyOptional({
    isArray: true,
  })
  @Allow()
 exampleProperty?: string[];
}

while this code doesn't error:

class ExampleDto {
  @ApiProperty({
    isArray: true,
  })
  @Allow()
 exampleProperty!: string[];
}
darraghoriordan commented 2 years ago

Ah nice one the optionality might have changed the AST. i'll take a look at this soon.

Out of interest, what behaviour would you expect here for primitive arrays - do you set @Type(()=> String) here or not?

iddan-flycode commented 2 years ago

For primitive types I rather not use the @type decorator. I think it should be required only when needed by the library to transform the DTO

On 16 Dec 2021, at 0:40, darraghoriordan @.***> wrote:

 Ah nice one the optionality might have changed the AST. i'll take a look at this soon.

Out of interest, what behaviour would you expect here for primitive arrays - do you set @type(()=> String) here or not?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android.

darraghoriordan commented 2 years ago

Hey!

This is fixed in 3.9.0 - I had to slightly change the way arrays are detected with optional properties.

I added your cases above to the test suite and it all seems ok.

thanks for the bug report!

dar

iddan-flycode commented 2 years ago

Thank you 🙏