Skip to content
AutoMapper TypeScript
Esc
navigateopen⌘Jpreview

typeConverter

Convert every matching source and destination metadata type within one mapping.

JavaScript permits a value to be assigned even when TypeScript metadata differs. A type converter makes the conversion explicit for every matching property pair in one mapping.

createMap(
  mapper,
  Source,
  Destination,
  typeConverter(String, Number, (value) => Number.parseInt(value, 10)),
  typeConverter(String, Date, (value) => new Date(value)),
  typeConverter(String, Boolean, (value) => value === 'true'),
);
const destination = mapper.map(source, Source, Destination);

Converters support four metadata shapes:

  • Type to Type;
  • Type to [Type];
  • [Type] to Type;
  • [Type] to [Type].
typeConverter([String], [Number], (values) =>
  values.map((value) => Number.parseInt(value, 10)),
);

Use convertUsing() when the conversion should apply to one destination member instead of every matching metadata pair.

Last updated on July 16, 2026

Was this page helpful?