Type

NarrowField

@ng-forge/dynamic-forms

Narrow a field definition based on its type property. Use this to get proper type inference when working with field unions.

Signature

type NarrowField<T> = T extends { type: infer TType } ? (TType extends AvailableFieldTypes ? ExtractField<TType> : T) : T;

Type Parameters

NameConstraintDefaultDescription
T---

Examples

function processField<T extends RegisteredFieldTypes>(field: T): NarrowField<T> {
  return field as NarrowField<T>;
}