#PartialType does not mark the fields as optional

12 messages · Page 1 of 1 (latest)

proper root
#
export class CreateCoffeeDto {
  @IsString()
  readonly name: string;

  @IsString()
  readonly brand: string;

  @IsString({ each: true })
  readonly flavors: Array<string>;
}

And then:

export class UpdateCoffeeDto extends PartialType(CreateCoffeeDto) {}

However I can see the Typescript still infers the properties of UpdateCoffeeDto as required. I would assume this to behave just as inbuilt Typescript's Partial utility type does instead. Is the above really intended behavior?

limpid zenith
#

I believe they should be optonal. Got a reproduction showing they aren't?

proper root
#

This should be complaining that brand is optional

limpid zenith
#

Depends on the strictness of your tsconfig. What happens when you hover on brand?

proper root
#

Oh I just noticed that nest defaults to non strict null checks

#

Okay thats another surprise

limpid zenith
#

With a very weak tsconfig (no strict options applied) you can do this

limpid zenith
proper root
#

Yeah with fixed tsconfig it works fine

#

I see

#

Okay, thanks