When both source and destination properties are equal (name and type) auto mapping map can be used. When there is property mismatch in mapping interfaces, extra member configuration is required by TypeScript.
interfaceSource { dateFrom:string; dateTo:string;}interfaceDestination { dateFrom:string; dateTo:string;}constSourceToDestination=newMappingPair<Source,Destination>();constconfig=newMapperConfiguration(cfg => {// automaticly map all source members to destination members without// an explicit member configurationcfg.createAutoMap(SourceToDestination, {});});
Bear in mind that each property from source object is mapped to the destination even when destination object does not declare this property in its interface. If you need to exclude some source properties from mapping you can ignored them by configuring specific source members.
constconfig=newMapperConfiguration(cfg => {// automaticly map all source members except "foo" propertycfg.createAutoMap(SourceToDestination, {}).forSourceMember('foo', opt =>opt.ignore());});
Strict mapping
This mapping requires full configuration of all destination members. Extra source properties are ignored during this strategy.
TypeScript provides necessary type checking for member configuration securing that all destination members are configured.
Prefer this strategy if you need all configured properties to be present in destination object.
interfaceSource { same:string; sourceExtra:string;}interfaceDestination { same:string; destinationExtra:string;}constSourceToDestination=newMappingPair<Source,Destination>();constconfig=newMapperConfiguration(cfg => {// with strict map, destination member configuration is required for// each individual member, even for members that could be automapped.cfg.createStrictMap(SourceToDestination, {// members that are defined in both Source and Destination// have .auto() option to explicitly enable auto mapping.same: opt =>opt.auto(),// explicit mapping from sourcedestinationExtra: opt =>opt.mapFrom(src =>src.sourceExtra) });});
Default mapping
Allows partial configuration of destination members. Full manual mapping, each destination member should have defined source to be mapped.