Libraries
    Preparing search index...

    Class PropertyMappingBuilder<TFromSchema, TToSchema, TKey, TUnmapped, TRegistered>

    Intermediate builder returned by for(). Provides three strategies to configure how the selected target property is populated:

    • from() — copy from a source property
    • compute() — compute from the entire source object
    • ignore() — explicitly skip the property

    Type Parameters

    • TFromSchema extends ObjectSchemaBuilder<any, any, any>
    • TToSchema extends ObjectSchemaBuilder<any, any, any>
    • TKey extends string
    • TUnmapped extends string
    • TRegistered = never
    Index

    Constructors

    Methods

    Constructors

    Methods

    • Computes the target property value from the entire source object. Supports both sync and async functions.

      Parameters

      • fn:
            | (
                (
                    obj: InferType<TFromSchema>,
                ) => SchemaPropertyInferredType<TToSchema, TKey>
            )
            | (
                (
                    obj: InferType<TFromSchema>,
                ) => Promise<SchemaPropertyInferredType<TToSchema, TKey>>
            )

      Returns Mapper<TFromSchema, TToSchema, Exclude<TUnmapped, TKey>, TRegistered>

    • Maps the target property from a source property. The selector receives the source schema's PropertyDescriptorTree and supports nested paths (e.g. (s) => s.address.city).

      Type compatibility is enforced: only source properties whose inferred type is assignable to the target property type will appear in the selector callback.

      Under strictFunctionTypes, the setValue and getValue constraints provide bidirectional type checking:

      • setValue contravariance rejects source schemas with extra properties
      • getValue covariance rejects source schemas with missing properties
      • registered mappings widen the constraint via intersection

      Type Parameters

      • TReturn extends {
            "[SYMBOL_SCHEMA_PROPERTY_DESCRIPTOR]": {
                getValue: (obj: any) => { success: boolean; value?: any };
                setValue: (obj: any, value: any) => any;
                getSchema(): SchemaBuilder<any, any, any>;
            };
        }

      Parameters

      • selector: (
            tree: PropertyDescriptorTree<
                TFromSchema,
                TFromSchema,
                SchemaPropertyInferredType<TToSchema, TKey>,
            >,
        ) => TReturn
      • ..._args: [TReturn] extends [never]
            ? [
                error: `Property '${TKey}': source property type is not assignable to the target property type. Use compute() instead.`,
            ]
            : IsFromCompatible<TReturn, TToSchema, TKey, TRegistered> extends true
                ? []
                : [
                    error: `Property '${TKey}': source property type is not assignable to the target property type. Use compute() instead.`,
                ]

      Returns Mapper<TFromSchema, TToSchema, Exclude<TUnmapped, TKey>, TRegistered>