Skip to content
AutoMapper TypeScript
Esc
navigateopen⌘Jpreview

condition

Map a matching source member only when a predicate succeeds.

forMember(
  (destination) => destination.petName,
  condition((source) => source.hasPet),
);

If the predicate is truthy, AutoMapper maps the conventionally matching source member. Otherwise the destination is undefined.

Provide a default for the false branch:

forMember(
  (destination) => destination.petName,
  condition((source) => source.hasPet, 'No pet'),
);

Last updated on July 16, 2026

Was this page helpful?