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

fix: <Transformer "class-transformer" metadata cannot be inherited for "CreateClassDto" I'm using Mapped-Type/@nestjs> #566

Closed
chanphiromsok opened this issue Jan 22, 2021 · 6 comments
Labels
type: fix Issues describing a broken feature.

Comments

@chanphiromsok
Copy link

chanphiromsok commented Jan 22, 2021

Description

Minimal code-snippet showcasing the problem

export class CreateClassDto {
  @IsOptional()
  @IsNumber()
  id: number;

  @ApiProperty({ example: 'CLASS-1' })
  @IsString()
  @IsNotEmpty()
  class_name: string;

  @ApiProperty({ example: '1' })
  @IsNotEmpty()
  @IsNumberString()
  floor: string;

  @ApiProperty({ example: 'This classe include yoga hit and aerobics' })
  @IsString()
  @IsOptional()
  description: string;

  @ApiProperty({ example: 1, description: 'staff id ' })
  @IsNumber()
  @IsOptional()
  creator_id: number;
}
===========This class I extends from CreateClassDto and it got error
import { PartialType } from '@nestjs/mapped-types';
import { CreateClassDto } from './create-class.dto';

export class UpdateClassDto extends PartialType(CreateClassDto) {}


==========Error Message ====
[Nest] 15036   - 01/22/2021, 3:15:49 PM   [MappedTypes] Transformer ("class-transformer") metadata cannot be inherited for "CreateClassDto" class.
[Nest] 15036   - 01/22/2021, 3:15:49 PM   [MappedTypes] Object:
{
  "code": "MODULE_NOT_FOUND",
  "requireStack": [
    "/Users/rom/Documents/workspace/gym-project/gym-api/node_modules/@nestjs/mapped-types/dist/type-helpers.utils.js",
    "/Users/rom/Documents/workspace/gym-project/gym-api/node_modules/@nestjs/mapped-types/dist/intersection-type.helper.js",
    "/Users/rom/Documents/workspace/gym-project/gym-api/node_modules/@nestjs/mapped-types/dist/index.js",
    "/Users/rom/Documents/workspace/gym-project/gym-api/node_modules/@nestjs/mapped-types/index.js",
    "/Users/rom/Documents/workspace/gym-project/gym-api/node_modules/@nestjs/swagger/dist/type-helpers/intersection-type.helper.js",
    "/Users/rom/Documents/workspace/gym-project/gym-api/node_modules/@nestjs/swagger/dist/type-helpers/index.js",
    "/Users/rom/Documents/workspace/gym-project/gym-api/node_modules/@nestjs/swagger/dist/index.js",
    "/Users/rom/Documents/workspace/gym-project/gym-api/node_modules/@nestjs/swagger/index.js",
    "/Users/rom/Documents/workspace/gym-project/gym-api/dist/config/swagger/config-swagger.js",
    "/Users/rom/Documents/workspace/gym-project/gym-api/dist/main.js"
  ]
}

Expected behavior

Actual behavior

@chanphiromsok chanphiromsok added status: needs triage Issues which needs to be reproduced to be verified report. type: fix Issues describing a broken feature. labels Jan 22, 2021
@chanphiromsok chanphiromsok changed the title fix: <Transformer "class-transformer" metadata cannot be inherited for "CreateClassDt" Im Use Mapped-Type nestjs> fix: <Transformer "class-transformer" metadata cannot be inherited for "CreateClassDto" I'm using Mapped-Type/@nestjs> Jan 22, 2021
@chanphiromsok
Copy link
Author

chanphiromsok commented Jan 26, 2021

"dependencies": {
    "@nestjs/mapped-types": "^0.1.1",
    "class-transformer": "0.3.1",
  },

In case everyone meets this problem just downgrade package class-transformer to 0.3.1 and @nestjs/mapped-types to 0.1.1

@NoNameProvided
Copy link
Member

Reopening as downgrading is not a solution for forever.

Looking at your code the error comes from the Nest package not us. Maybe open an issue there and link it back? I believe we will need some co-opeartion to solve this.

@asomethings
Copy link

asomethings commented Jan 27, 2021

This can be resolved by upgrading @nestjs/mapped-types to v0.2.0 or newer. So it seems closing this is appropriate @NoNameProvided.

@gevuong
Copy link

gevuong commented Feb 4, 2021

I encountered a similar error, both suggestions provided above worked for me:

  1. upgrade @nestjs/mapped-types to 0.3.0 (latest), or
  2. downgrading class-transformer and mapped-types to 0.3.1 and 0.1.0, respectively.

Note: I had to update @nestjs/graphql from 7.9.4 to 7.9.8 (latest) in order to update its mapped-types dependency to 0.3.0 (latest).

@NoNameProvided
Copy link
Member

Thanks, closing as solved.

@NoNameProvided NoNameProvided added type: fix Issues describing a broken feature. status: cannot reproduce Bug reports which cannot be reproduced. and removed status: needs triage Issues which needs to be reproduced to be verified report. type: fix Issues describing a broken feature. status: cannot reproduce Bug reports which cannot be reproduced. labels Feb 14, 2021
@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 17, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type: fix Issues describing a broken feature.
Development

No branches or pull requests

4 participants