import { InjectionToken, Type } from '@angular/core'; import { AbstractControl, ValidationErrors, UntypedFormGroup, UntypedFormArray, UntypedFormControl, ControlValueAccessor, Validator } from '@angular/forms'; import { Observable, Subject } from 'rxjs'; import { Nilable } from 'tsdef'; type Controls = { [K in keyof T]-?: AbstractControl; }; type ControlsNames = { [K in keyof T]-?: K; }; type ControlMap = { [K in keyof T]-?: V; }; type ControlsType = { [K in keyof T]-?: T[K] extends any[] ? TypedFormArray : TypedFormControl | (T[K] extends {} ? TypedFormGroup : never); }; type OneOfControlsTypes = ControlsType[keyof ControlsType]; type NewFormErrorsType = { [K in keyof T]-?: T[K] extends any[] ? Record : ValidationErrors; }; type NewFormErrors = null | Partial & { formGroup?: ValidationErrors; }>; interface TypedAbstractControl extends AbstractControl { value: TValue; valueChanges: Observable; setValue(value: TValue, options?: Parameters[1]): void; patchValue(value: Partial, options?: Parameters[1]): void; } interface TypedFormGroup extends UntypedFormGroup { value: TValue; valueChanges: Observable; controls: ControlsType; setValue(value: TValue, options?: Parameters[1]): void; patchValue(value: Partial, options?: Parameters[1]): void; getRawValue(): TValue; } interface TypedFormArray extends UntypedFormArray { value: TValue; valueChanges: Observable; controls: TypedAbstractControl[]; setValue(value: TValue, options?: Parameters[1]): void; patchValue(value: TValue, options?: Parameters[1]): void; getRawValue(): TValue; } interface TypedFormControl extends UntypedFormControl { value: TValue; valueChanges: Observable; setValue(value: TValue, options?: Parameters[1]): void; patchValue(value: Partial, options?: Parameters[1]): void; } type KeysWithType = { [K in keyof T]: T[K] extends V ? K : never; }[keyof T]; type ArrayPropertyKey = KeysWithType>; type ArrayPropertyValue = ArrayPropertyKey> = T[K] extends Array ? U : never; declare function subformComponentProviders(component: any): { provide: InjectionToken; useExisting: Type; multi?: boolean; }[]; declare class MissingFormControlsError extends Error { constructor(missingFormControls: T[]); } declare const NGX_SUB_FORM_HANDLE_VALUE_CHANGES_RATE_STRATEGIES: { debounce: (time: number) => (obs: Observable) => Observable; }; /** * Easily unsubscribe from an observable stream by appending `takeUntilDestroyed(this)` to the observable pipe. * If the component already has a `ngOnDestroy` method defined, it will call this first. */ declare function takeUntilDestroyed(component: any): (source: Observable) => Observable; type Nullable = T | null; type NullableObject = { [P in keyof T]: Nullable; }; type TypedValidatorFn = (formGroup: TypedFormGroup) => ValidationErrors | null; type TypedAsyncValidatorFn = (formGroup: TypedFormGroup) => Promise | Observable; interface FormGroupOptions { /** * @description The list of validators applied to a control. */ validators?: TypedValidatorFn | TypedValidatorFn[] | null; /** * @description The list of async validators applied to control. */ asyncValidators?: TypedAsyncValidatorFn | TypedAsyncValidatorFn[] | null; /** * @description The event name for control to update upon. */ updateOn?: 'change' | 'blur' | 'submit'; } interface NgxFormWithArrayControls { createFormArrayControl(key: ArrayPropertyKey, value: ArrayPropertyValue): UntypedFormControl; } interface ComponentHooks { onDestroy: Observable; afterViewInit: Observable; } interface FormBindings { readonly writeValue$: Observable>; readonly registerOnChange$: Observable<(formValue: ControlInterface | null) => void>; readonly registerOnTouched$: Observable<() => void>; readonly setDisabledState$: Observable; } type ControlValueAccessorComponentInstance = Object & Partial & Record>; interface NgxSubForm { readonly formGroup: TypedFormGroup; readonly formControlNames: ControlsNames; readonly formGroupErrors: NewFormErrors; readonly createFormArrayControl: CreateFormArrayControlMethod; readonly controlValue$: Observable>; } type CreateFormArrayControlMethod = >(key: K, initialValue: ArrayPropertyValue) => UntypedFormControl; interface NgxRootForm extends NgxSubForm { } interface NgxSubFormArrayOptions { createFormArrayControl?: CreateFormArrayControlMethod; } interface NgxSubFormRemapOptions { toFormGroup: (obj: ControlInterface) => FormInterface; fromFormGroup: (formValue: FormInterface) => ControlInterface; } type AreTypesSimilar = T extends U ? (U extends T ? true : false) : false; type NgxSubFormRemap = AreTypesSimilar extends true ? Partial> : NgxSubFormRemapOptions; type NgxSubFormArray = ArrayPropertyKey extends never ? {} : NgxSubFormArrayOptions; type NgxSubFormOptions = { formType: FormType; formControls: Controls; formGroupOptions?: FormGroupOptions; emitNullOnDestroy?: boolean; emitInitialValueOnInit?: boolean; componentHooks?: ComponentHooks; touched$?: Observable; } & NgxSubFormRemap & NgxSubFormArray; type NgxRootFormOptions = NgxSubFormOptions & { input$: Observable; output$: Subject; disabled$?: Observable; manualSave$?: Observable; outputFilterPredicate?: (currentInputValue: FormInterface, outputValue: FormInterface) => boolean; handleEmissionRate?: (obs$: Observable) => Observable; }; declare enum FormType { SUB = "Sub", ROOT = "Root" } type NgxFormOptions = NgxSubFormOptions | NgxRootFormOptions; declare const getFormGroupErrors: (formGroup: TypedFormGroup) => NewFormErrors; interface FormArrayWrapper { key: keyof FormInterface; control: UntypedFormArray; } declare function createFormDataFromOptions(options: NgxSubFormOptions): { formGroup: TypedFormGroup; defaultValues: FormInterface; formControlNames: ControlsNames; formArrays: FormArrayWrapper[]; }; declare const handleFormArrays: (formArrayWrappers: FormArrayWrapper[], obj: FormInterface, createFormArrayControl: Required>["createFormArrayControl"]) => void; declare function createForm(componentInstance: ControlValueAccessorComponentInstance, options: NgxRootFormOptions): NgxRootForm; declare function createForm(componentInstance: ControlValueAccessorComponentInstance, options: NgxSubFormOptions): NgxSubForm; export { FormType, MissingFormControlsError, NGX_SUB_FORM_HANDLE_VALUE_CHANGES_RATE_STRATEGIES, createForm, createFormDataFromOptions, getFormGroupErrors, handleFormArrays, subformComponentProviders, takeUntilDestroyed }; export type { AreTypesSimilar, ArrayPropertyKey, ArrayPropertyValue, ComponentHooks, ControlMap, ControlValueAccessorComponentInstance, Controls, ControlsNames, ControlsType, CreateFormArrayControlMethod, FormBindings, FormGroupOptions, KeysWithType, NewFormErrors, NewFormErrorsType, NgxFormOptions, NgxFormWithArrayControls, NgxRootForm, NgxRootFormOptions, NgxSubForm, NgxSubFormArrayOptions, NgxSubFormOptions, NgxSubFormRemapOptions, NullableObject, OneOfControlsTypes, TypedAbstractControl, TypedAsyncValidatorFn, TypedFormArray, TypedFormControl, TypedFormGroup, TypedValidatorFn };