Git Product home page Git Product logo

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>' about mapped-types HOT 6 CLOSED

praveendodda07 avatar praveendodda07 commented on April 28, 2024 2
Class 'CreateUserDto' incorrectly extends base class 'RemoveFieldsWithType, Function>'. Property 'status' is optional in type 'CreateUserDto' but required in type 'RemoveFieldsWithType, Function>'

from mapped-types.

Comments (6)

huthaifaa avatar huthaifaa commented on April 28, 2024 2

Fixed in v2.0.1

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

from mapped-types.

micalevisk avatar micalevisk commented on April 28, 2024 1

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 😸

from mapped-types.

huthaifaa avatar huthaifaa commented on April 28, 2024 1
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.

from mapped-types.

kamilmysliwiec avatar kamilmysliwiec commented on April 28, 2024

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

from mapped-types.

huthaifaa avatar huthaifaa commented on April 28, 2024

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.

from mapped-types.

kamilmysliwiec avatar kamilmysliwiec commented on April 28, 2024

Fixed in v2.0.1

from mapped-types.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.