Skip to content

Is discriminator in @Type working for collections? #1441

Open
@CaunicAndreiAteliere

Description

@CaunicAndreiAteliere

I was trying to use the discriminator in @type as per documentation:

  @Type(() => Photo, {
    discriminator: {
      property: '__type',
      subTypes: [
        { value: Landscape, name: 'landscape' },
        { value: Portrait, name: 'portrait' },
        { value: UnderWater, name: 'underwater' },
      ],
    },
  })
  topPhoto: Landscape | Portrait | UnderWater;

But my use case involves to use it in a Map construct like this:

  @Type(() => Photo, {
    discriminator: {
      property: '__type',
      subTypes: [
        { value: Landscape, name: 'landscape' },
        { value: Portrait, name: 'portrait' },
        { value: UnderWater, name: 'underwater' },
      ],
    },
  })
  topPhoto: Map<string, Landscape | Portrait | UnderWater>;               <-------my scenario

When testing I found out that the discriminator doesn't work anymore and I cannot find out an workaround...

Can you please help me understand how to use it in order to have sub-types based on a property in a Map construct and not the base class?

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: questionQuestions about the usage of the library.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions