Skip to content
AutoMapper TypeScript
Esc
navigateopen⌘Jpreview
On this page

forMember

Select a destination path and assign one member-mapping function, with an optional precondition.

forMember() targets one destination member and assigns its transformation:

The callbacks are contextually typed from the source and destination passed to createMap().

createMap<User, UserDto>(mapper: Mapper, source: ModelIdentifier<User>, destination: ModelIdentifier<UserDto>, ...mappingConfigFns: (MappingConfiguration<User, UserDto> | undefined)[]): Mapping<User, UserDto> (+1 overload)createMap(
  const mapper: Mappermapper,
  class UserUser,
  class UserDtoUserDto,
  forMember<User, UserDto, string>(selector: Selector<UserDto, string>, preCondOrMapMemberFn: PreConditionReturn<User, UserDto, string> | MemberMapReturn<User, UserDto, string> | undefined, mapMemberFn?: MemberMapReturn<User, UserDto, string> | undefined): MappingConfiguration<User, UserDto>forMember(
    (
destination: UserDto
destination
) => destination: UserDtodestination.UserDto.fullName: stringfullName,
mapFrom<User, UserDto, string>(from: ((source: User) => MaybePromise<string>) | Resolver<User, UserDto, string>): MapFromReturn<User, UserDto, string>mapFrom((
source: User
source
) => `${source: Usersource.User.firstName: stringfirstName} ${source: Usersource.User.lastName: stringlastName}`),
), );

The destination selector is strongly typed. The second argument determines how AutoMapper produces that value.

Precondition

Add preCondition() before the member function to skip its work unless a source predicate succeeds. An optional default is assigned when the predicate fails.

forMember(
  (destination) => destination.fullName,
  preCondition((source) => source.visible, "Hidden user"),
  mapFrom((source) => `${source.firstName} ${source.lastName}`),
);

Use custom members for exceptions to convention. If almost every destination path needs one, an explicit transformation may be easier to understand.

Last updated on July 16, 2026

Was this page helpful?