How to define union type metadata in automapper

Viewed 56

I'm using automapper with Pojo strategy I have to define metadata for it, but "postalCode" field have a union type.

      PojosMetadataMap.create<FrontendData>("FrontendData", {
        address: String,
        postalCode: null | number,
        latitude: Number,
        longitude: Number,
     });

Unfortunately the syntax null postalCode: null | number does not work. I have looking in documentation but there was nothing about using union types with this strategy - https://automapperts.netlify.app/docs/strategies/pojos/. If you have solved a similar issue, I'd be thankful for your help

1 Answers

I asked the same question in github issue and got an answer from the developer of the library:

As of the moment, there's no union support for metadata. number | null is still Number in this case. If the source postalCode is null then it will be mapped to null, if the source postalCode is undefined then it will be mapped to undefined. You can use undefinedSubstitution(null) to convert it to null if the source is undefined

You can find github issue here

Related