Type

InferFormValue

@ng-forge/dynamic-forms

Infer form value type from fields array or FormConfig. Recursively processes nested structures and merges the results. Limited to 5 levels of nesting to prevent infinite type instantiation.

Signature

type InferFormValue<T> =
  ExtractFields<T> extends readonly RegisteredFieldTypes[]
    ? InferFormValueWithDepth<ExtractFields<T> extends RegisteredFieldTypes[] ? ExtractFields<T> : [...ExtractFields<T>], 5>
    : never;

Type Parameters

NameConstraintDefaultDescription
T---

Examples

// From fields array
const fields = [
  { type: 'input', key: 'email', value: '', required: true },
  { type: 'input', key: 'name', value: '' }
] as const;
type FieldsValue = InferFormValue<typeof fields>;

// From FormConfig
const config = {
  fields: [
    { type: 'input', key: 'email', value: '', required: true },
    { type: 'input', key: 'name', value: '' }
  ]
} as const satisfies FormConfig;
type ConfigValue = InferFormValue<typeof config>;

// Result: { email: string; name?: string }