How to map when using custom generic type in TS #372
Answered
by
micalevisk
renatoargh
asked this question in
Q&A
-
Hello 👋 Currently I have this: export default class Email { // <--- destination
@AutoMap()
public readonly id: string
@AutoMap()
public readonly address: string
@AutoMap()
public readonly contactPerson: Nullable<string>
constructor(
_id: string,
_address: string,
_contactPerson: Nullable<string> = null,
) {
this.id = _id
this.address = _address
this.contactPerson = _contactPerson
}
}
export class ApiCreateContactEmail { // <--- source
@AutoMap()
@ApiProperty({
example: 'eb5b4068-0322-43fb-8233-fa8dd708c4dc',
required: true,
description: 'Unique identifier for the email',
format: 'uuid',
})
id: string
@AutoMap()
@ApiProperty({
example: examples.email,
required: true,
description: 'Email address',
})
address: string
@AutoMap()
@ApiProperty({
example: examples.person2.name,
required: false,
description: 'Contact person for the address',
})
contactPerson: Nullable<string>
} Where When I try to convert them, I get this ugly error:
If I comment out What would be the correct way to fix this? PS.: Mapper configuration is super simple: export const mapper = createMapper({
name: 'contactMapper',
pluginInitializer: classes,
})
mapper.createMap(ApiCreateContactEmail, Email) Thanks a lot! :) |
Beta Was this translation helpful? Give feedback.
Answered by
micalevisk
Nov 4, 2021
Replies: 1 comment 2 replies
-
what if you use @AutoMap({ typeFn: () => String })
@ApiProperty({
example: examples.person2.name,
required: false,
description: 'Contact person for the address',
})
contactPerson: Nullable<string> https://automapperts.netlify.app/docs/plugins-system/classes-limitations/#strict-mode |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
nartc
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
what if you use
https://automapperts.netlify.app/docs/plugins-system/classes-limitations/#strict-mode