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

Created on 22 Jan 2021  路  6Comments  路  Source: typestack/class-transformer

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

fix

Most helpful comment

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

All 6 comments

"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

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.

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

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).

Thanks, closing as solved.

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ERPedersen picture ERPedersen  路  4Comments

VivienAdnot picture VivienAdnot  路  6Comments

AckerApple picture AckerApple  路  5Comments

ceopaludetto picture ceopaludetto  路  3Comments

weeco picture weeco  路  5Comments