Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect mappings when passing invalid types #541

Open
3 of 9 tasks
ClassTerr opened this issue Mar 28, 2023 · 0 comments
Open
3 of 9 tasks

Incorrect mappings when passing invalid types #541

ClassTerr opened this issue Mar 28, 2023 · 0 comments
Labels
bug Something isn't working

Comments

@ClassTerr
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

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

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.

Screenshots

No response

Minimum reproduction code

https://stackblitz.com/edit/typescript-1cd3bs?file=index.ts

Package

  • I don't know.
  • @automapper/core
  • @automapper/classes
  • @automapper/nestjs
  • @automapper/pojos
  • @automapper/mikro
  • @automapper/sequelize
  • Other (see below)

Other package and its version

No response

AutoMapper version

8.7.7

Additional context

No response

@ClassTerr ClassTerr added the bug Something isn't working label Mar 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant