Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Class 'CreateUserDto' incorrectly extends base class 'RemoveFieldsWithType<Partial<User>, Function>'. Property 'status' is optional in type 'CreateUserDto' but required in type 'RemoveFieldsWithType<Partial<User>, Function>' #1121

Closed
2 of 4 tasks
praveendodda07 opened this issue Jun 18, 2023 · 6 comments

Comments

@praveendodda07
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

In version 2.0.0 we are getting this error. user Partial

Minimum reproduction code

https://github.com/nestjs/mapped-types

Steps to reproduce

install @nestjs/mapped-types with 2.0.0 version
User "Partial" method from it.
Getting the error like: Class 'CreateUserDto' incorrectly extends base class 'RemoveFieldsWithType<Partial, Function>'.
Property 'status' is optional in type 'CreateUserDto' but required in type 'RemoveFieldsWithType<Partial, Function>'.

Expected behavior

This error should not come.

Package version

2.0.0

Node.js version

14.21.3

In which operating systems have you tested?

  • macOS
  • Windows
  • Linux

Other

No response

@kamilmysliwiec
Copy link
Member

Please provide a minimum reproduction repository (Git repository/StackBlitz/CodeSandbox project).

@huthaifaa
Copy link

Getting the same error after upgrading to Nest10 today. Amazing work on the release, great job!
Made a small workaround by using the working version of partialtype.helper in version 1.2.

I believe it should be an easy fix from the team. Looking forward to it.

The error is caused when using a partial type, and says that the rest of the data is required, although it's a partial type.

@micalevisk
Copy link
Member

I believe it should be an easy fix from the team

it could be if someone provide us some code or the steps to create a repro of such issue, at least 😸

@huthaifaa
Copy link

huthaifaa commented Jun 20, 2023

import { PartialType } from '@nestjs/mapped-types';
import {
  IsBoolean,
  IsEmpty,
  IsOptional,
  IsString,
} from 'class-validator';

export class SpCreateSpecializationDto {
  @IsString()
  name: string;

  @IsString()
  description?: string;


  @IsOptional()
  @IsBoolean()
  isPublished?: boolean;
}

export class SpUpdateSpecializationDto extends PartialType(
  SpCreateSpecializationDto,
) {
  @IsEmpty()
  isPublished?: boolean;

}

I found it can be fixed by using omit, like this:

export class SpUpdateSpecializationDto extends PartialType(
  OmitType(SpCreateSpecializationDto, ['isPublished'] as const),
) {
  @IsEmpty()
  isPublished?: undefined;
}

This removes the error of:
Class 'SpUpdateSpecializationDto' incorrectly extends base class 'RemoveFieldsWithType<Partial<SpCreateSpecializationDto>, Function>'. Property 'courseIds' is optional in type 'SpUpdateSpecializationDto' but required in type 'RemoveFieldsWithType<Partial<SpCreateSpecializationDto>, Function>'.

I hope this is helpful.

@kamilmysliwiec
Copy link
Member

Fixed in v2.0.1

@huthaifaa
Copy link

Fixed in v2.0.1

Thank you so much, really a big fan of your work! LEGAND

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants