mapper
mapper copied to clipboard
[classes] Auto mapping `Date` from `null` resolves to `undefined` wrongly
Is there an existing issue for this?
- [X] I have searched the existing issues
Describe the issue
When using @AutoMap({ typefn: () => null }) for some field that could be Date | null, the destination end up with undefined instead of null
I believe this is a bug because this doesn't happen in v8. But this also could be a limitation, I'm unsure.
Models/DTOs/VMs
class Foo {
@AutoMap({ typeFn: () => Number })
someNumber: number | null
@AutoMap({ typeFn: () => Date })
someDate: Date | null
}
class FooVm {
@AutoMap()
someNumber?: number
@AutoMap()
someDate: Date | null
}
Mapping configuration
const mapper = createMapper({
name: '',
pluginInitializer: classes,
})
mapper.createMap(Foo, FooVm)
// ...
const foo: Foo = {
someDate: null,
someNumber: 123,
}
const fooVm = mapper.map(foo, FooVm, Foo)
console.log(fooVm)
/*
FooVm { someNumber: 123, someDate: undefined }
*/
Steps to reproduce
No response
Expected behavior
mapper.map(foo, FooVm, Foo) should return:
FooVm { someNumber: 123, someDate: null }
because we're reyling on AutoMap
Minimum reproduction code
https://replit.com/@micalevisk/automapper
Package
- [ ] I don't know.
- [ ]
@automapper/core - [X]
@automapper/classes - [ ]
@automapper/nestjs - [ ]
@automapper/pojos - [ ]
@automapper/mikro - [ ]
@automapper/sequelize - [ ] Other (see below)
Other package and its version
No response
AutoMapper version
7.3.14
Additional context
No response