An object, where every property name must match a property name in the desired output type.
Every property value must be a MapperSchemaValue
.
▶Example 1
Example 1
interface Input { inString: string; inNumber: number; inOptionalString: string | undefined; } interface Output { outString: string; } let mapperSchema: ObjectMapperSchema<Input, Output> = { outString: (input: Input) => input.inString, }; mapperSchema = { outString: (input, _context: undefined | void) => input.inString, }; mapperSchema = { outString: "inString", // This is okay, since `Input["inString"]` has the same type as `Output["outString"]` }; // mapperSchema = { // outString: "inNumber", // This will error. `inNumber` has type `number`, so can't be used to populate `outString` which requires a `string`. // }; // mapperSchema = { // outString: "inOptionalString", // This will error. `inOptionalString` can be `undefined`, which isn't compatible with `string` (when strict null checks are on). // }; interface Context { capitalize: boolean; } const mapperSchemaWithContext: ObjectMapperSchema<Input, Output, Context> = { outString: (input, context) => context.capitalize ? input.inString.toUpperCase() : input.inString, };
[TOutputKey in keyof TOutput]-?: MapperSchemaValue<TInput, TOutput, TContext, TOutputKey>