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

property is undefined after mapping #595

Open
3 of 9 tasks
maxime-aubry opened this issue Feb 6, 2024 · 2 comments
Open
3 of 9 tasks

property is undefined after mapping #595

maxime-aubry opened this issue Feb 6, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@maxime-aubry
Copy link

maxime-aubry commented Feb 6, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Describe the issue

After is called the mapper, i get a date as a string, as i wanted.
But 'id' property is undefined.
I must add 'forMember' function for 'id' property too.

Models/DTOs/VMs

import { AutoMap } from '@automapper/classes';

export class TransformationAuditGetAllResponseState {
  @AutoMap()
  id!: string;

  @AutoMap()
  transformationDate!: string;
}

export class TransformationAuditGetAllResponseDto {
  @AutoMap()
  id!: string;

  @AutoMap()
  transformationDate!: Date;
}

Mapping configuration

export const mapper: Mapper = createMapper({
  strategyInitializer: classes(),
});

createMap(
  mapper,
    TransformationAuditGetAllResponseDto,
    TransformationAuditGetAllResponseState,
  forMember(
      (dest: TransformationAuditGetAllResponseState) => dest.transformationDate,
    mapFrom((source: TransformationAuditGetAllResponseDto) => moment(source.transformationDate).format('DD/MM/YYYY hh:mm:ss A'))
  ),
);

Steps to reproduce

No response

Expected behavior

Value of 'id' property of TransformationAuditGetAllResponseDto should be mapped for 'id' property of TransformationAuditGetAllResponseState.

Screenshots

No response

Minimum reproduction code

No response

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.8.1

Additional context

typescript version : 5.3.3

@maxime-aubry maxime-aubry added the bug Something isn't working label Feb 6, 2024
@maxime-aubry
Copy link
Author

Mapper works if i add type on properties.

for example :

import { AutoMap } from '@automapper/classes';

export class TransformationAuditGetAllResponseState {
  @AutoMap(() => String)
  id!: string;

  @AutoMap(() => String)
  transformationDate!: string;
}

export class TransformationAuditGetAllResponseDto {
  @AutoMap(() => String)
  id!: string;

  @AutoMap(() => Date)
  transformationDate!: Date;

Is there a way to do with another way ?

@bradws
Copy link

bradws commented Feb 28, 2024

Yes I'm getting the same result as you. However it only seems to occur in my testing environment (I use vitest). If I run it as normal transpiled javascript, it is fine and I don't need to specify the ()=>String

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

2 participants