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
mapper.createMap(UserDto, User)
.forSelf(UserBriefcaseDto, (s) => s.userBriefcase)
// ⛔ generates error, but it should map NoteDto[] to Note[] (flatten userBriefcase.notes to self.notes) !!!
.forMember((dest)=>dest.addrCity, mapFrom((src) => src.userBriefcase.address.city))
.forMember((dest)=>dest.addrStreet, mapFrom((src) => src.userBriefcase.address.street))
.forMember((dest)=>dest.addrStreetNumber, mapFrom((src) => src.userBriefcase.address.streetNumber))
.forMember((dest)=>dest.addrHouseNumber, mapFrom((src) => src.userBriefcase.address.houseNumber))
.forMember((dest)=>dest.addrPostalCode, mapFrom((src) => src.userBriefcase.address.postalCode));
Why version (2) with forSelf is not working ?
From what I understand in version (2) forSelf should map NoteDto[] to Note[] but I'm getting error:
Error:
Error at "notes" on undefined ({"email":"[email protected]","firstName":"Patryk","lastName":"Test","uniqueId":"PT-111","birthDate":"2008-10-08T22:00:00Z","phoneNumber":"534534534"})
---------------------------------------------------------------------
Original error: TypeError: Cannot read properties of undefined (reading 'name')
Error at "notes" on undefined ({"email":"pt-testowy
unknown
setMember
C:/packages/core/src/lib/map/map.ts:203
200 | * @param {TSource[]} sourceArray - the array of source items to map
201 | * @param destination - destination meta key
202 | * @param source - source meta key
> 203 | * @param {MapArrayOptions} options - the map options for this particular map operation
| ^ 204 | * @param {Mapper} mapper - the mapper instance
205 | * @param {ErrorHandler} errorHandler - error handler
206 | */
View compiled
map
C:/packages/core/src/lib/map/map.ts:259
This is a simplified case but .forSelf I wanted to apply in many other similar places where I use [] and manually mapping each array using forMember is cumbersome.
I am getting more and more gray hair because of this error.... What am I doing wrong?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I'm trying to create map between classes:
Config
Source
Destination
(1) Created map - manual mapping with forMember (working) ✔
(2) Created map - using forSelf (not working) ❌
Why version (2) with forSelf is not working ?
From what I understand in version (2)
forSelf
should mapNoteDto[]
toNote[]
but I'm getting error:This is a simplified case but .forSelf I wanted to apply in many other similar places where I use [] and manually mapping each array using forMember is cumbersome.
I am getting more and more gray hair because of this error....
What am I doing wrong?
Beta Was this translation helpful? Give feedback.
All reactions