You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using Automapper I expect that output of map method will transform input into exact type with only known fields with correct types.
But it isn't the case now. When class expects one type, but provided another mapping behaves very odd (examples attached).
Models/DTOs/VMs
class NestedClass {
@AutoMap()
myProp: string;
}
class Test {
@AutoMap()
title: string;
@AutoMap()
obj?: NestedClass;
@AutoMap(() => [NestedClass])
array?: NestedClass[];
}
Mapping configuration
// Create and export the mapper
export const mapper = createMapper({
strategyInitializer: classes(),
});
createMap(mapper, Test, Test);
createMap(mapper, NestedClass, NestedClass);
Steps to reproduce
No response
Expected behavior
It's complicated question since for different scenarios I would like to adjust rules for incorrect types, but in general I think the most appropriate solution would be just skip incorrect values or consider them as undefined. Things become more complicated when working with arrays. If some element of array is not valid but others are - I would certainly like to configure the behavior - skip or set as null or undefined. typeConverter is not appropriate here as I understand since you need to predict all of the cases for every single mapping.
Is there an existing issue for this?
Describe the issue
When using Automapper I expect that output of map method will transform input into exact type with only known fields with correct types.
But it isn't the case now. When class expects one type, but provided another mapping behaves very odd (examples attached).
Models/DTOs/VMs
Mapping configuration
Steps to reproduce
No response
Expected behavior
It's complicated question since for different scenarios I would like to adjust rules for incorrect types, but in general I think the most appropriate solution would be just skip incorrect values or consider them as
undefined
. Things become more complicated when working with arrays. If some element of array is not valid but others are - I would certainly like to configure the behavior - skip or set as null or undefined.typeConverter
is not appropriate here as I understand since you need to predict all of the cases for every single mapping.Screenshots
No response
Minimum reproduction code
https://stackblitz.com/edit/typescript-1cd3bs?file=index.ts
Package
@automapper/core
@automapper/classes
@automapper/nestjs
@automapper/pojos
@automapper/mikro
@automapper/sequelize
Other package and its version
No response
AutoMapper version
8.7.7
Additional context
No response
The text was updated successfully, but these errors were encountered: