Skip to content

fix: map number key converted to string #1356

Open
@andrea11

Description

@andrea11

Description

I am trying to use class-transformer with maps, and I having an issue using numbers as keys.
Minimal code-snippet showcasing the problem

I defined the following class:

export class Data {
  @Type(() => String)
  public map: Map<number, string>

  constructor(
    map: Map<number, string> = new Map<number, string>()
  ) {
    this.map = map
  }
}

when I do:

plainToInstance(Data, {map: {123: "test"}}

the key is converted from number to string

Expected behavior

The entry in the map should have 123 as key

Actual behavior

The entry in the map is "123" as key

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: needs triageIssues which needs to be reproduced to be verified report.type: fixIssues describing a broken feature.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions