namespace types

These types are used by the ObjectMapper. Here's the magic which makes object mapper schemas type safe and complete. You generally won't need to make use of these types within your own code; just ObjectMapper should be enough.

Interfaces

I
types.MapperFunction

A function that takes some input object, and an optional context object, and returns an output. This is used as part of an ObjectMapperSchema.

I
types.ObjectMapperFunction

A callable function, equivalent to calling ObjectMapper#map. It also exposes ObjectMapperFunction#schema as a readonly property.

Type Aliases

T
types.AllowInputKeyIfInputCanExtendOutput<TInput, TOutputValue> = [TInputKey in keyof TInput]: TInput[TInputKey] extends TOutputValue ? TInputKey : never[keyof TInput]

Given some object TInput, and some value TOutputValue, allows any key of TInput that can be assigned to TOutputValue.

T
types.ExactReturn<T> = T extends readonly unknown[] ? number extends T["length"] ? T extends (infer E)[] ? ExactReturn<E>[] : readonly ExactReturn<T[number]>[] : [K in keyof T]: ExactReturn<T[K]> : T extends object ? T & { readonly [ExactReturnKeys]?: keyof T; } : T

Brand an object type with a phantom property whose type is keyof T, so that a wider key set is NOT assignable to a narrower one. This makes mapper-produced object return types invariant in their key set: a mapper for a superset type can no longer be substituted where a mapper for a subset is expected.

T
types.OptionalArgIfUndefined<T> = T extends undefined ? T | void : T

An ObjectMapper can take an optional context. The context type is defined when you instantiate an ObjectMapper. If the context type is undefined, rather than passing undefined every time, you can just omit the property. (You can still pass undefined, for parity with the mappers that require a context.)