From 1e7d271fcbb6d59f43c4a9191ff8bdd057c156f4 Mon Sep 17 00:00:00 2001 From: ntziolis Date: Wed, 12 Feb 2020 16:39:01 +0100 Subject: [PATCH 01/15] feat(ControlsType): added typings for AbstractControls + FormArrays --- .../src/lib/ngx-sub-form-utils.ts | 35 ++++++++++++++++++- .../src/lib/ngx-sub-form.component.ts | 2 +- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/projects/ngx-sub-form/src/lib/ngx-sub-form-utils.ts b/projects/ngx-sub-form/src/lib/ngx-sub-form-utils.ts index 6f228615..6e489a66 100644 --- a/projects/ngx-sub-form/src/lib/ngx-sub-form-utils.ts +++ b/projects/ngx-sub-form/src/lib/ngx-sub-form-utils.ts @@ -19,7 +19,9 @@ export type ControlsNames = { [K in keyof T]-?: K }; export type ControlMap = { [K in keyof T]-?: V }; -export type ControlsType = { [K in keyof T]-?: T[K] extends any[] ? FormArray : AbstractControl }; +export type ControlsType = { + [K in keyof T]-?: T[K] extends any[] ? TypedFormArray : TypedAbstractControl; +}; export type FormErrorsType = { [K in keyof T]-?: T[K] extends any[] ? (null | ValidationErrors)[] : ValidationErrors; }; @@ -32,6 +34,37 @@ export type FormErrors = null | Partial< } >; +type Omit = Pick>; // can be removed when upgrading ts version +type UntypedControlBase = Omit< + TControl, + 'value' | 'valueChanges' | 'setValue' | 'patchValue' +>; + +export type TypedAbstractControl = { + value: TValue; + valueChanges: Observable; + setValue( + value: TValue, + options?: { + onlySelf?: boolean; + emitEvent?: boolean; + emitModelToViewChange?: boolean; + emitViewToModelChange?: boolean; + }, + ): void; + patchValue( + value: Partial, + options?: { + onlySelf?: boolean; + emitEvent?: boolean; + emitModelToViewChange?: boolean; + emitViewToModelChange?: boolean; + }, + ): void; +} & UntypedControlBase; + +export type TypedFormArray = TypedAbstractControl & UntypedControlBase; + export type KeysWithType = { [K in keyof T]: T[K] extends V ? K : never }[keyof T]; export type ArrayPropertyKey = KeysWithType>; diff --git a/projects/ngx-sub-form/src/lib/ngx-sub-form.component.ts b/projects/ngx-sub-form/src/lib/ngx-sub-form.component.ts index cfd03b05..a23b73e4 100644 --- a/projects/ngx-sub-form/src/lib/ngx-sub-form.component.ts +++ b/projects/ngx-sub-form/src/lib/ngx-sub-form.component.ts @@ -40,7 +40,7 @@ export abstract class NgxSubFormComponent; + return this.formGroup.controls as unknown as ControlsType; } public get formGroupValues(): Required { From b5e2ceed0733732870e89f7088298800f2aefc84 Mon Sep 17 00:00:00 2001 From: ntziolis Date: Sat, 15 Feb 2020 13:20:19 +0100 Subject: [PATCH 02/15] fix(formatting): ran yarn run prettier:write --- projects/ngx-sub-form/src/lib/ngx-sub-form.component.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/ngx-sub-form/src/lib/ngx-sub-form.component.ts b/projects/ngx-sub-form/src/lib/ngx-sub-form.component.ts index a23b73e4..30e4cd4e 100644 --- a/projects/ngx-sub-form/src/lib/ngx-sub-form.component.ts +++ b/projects/ngx-sub-form/src/lib/ngx-sub-form.component.ts @@ -40,7 +40,7 @@ export abstract class NgxSubFormComponent; + return (this.formGroup.controls as unknown) as ControlsType; } public get formGroupValues(): Required { From 4d303bd07e22e0d2563ebb60a8b2304d7cd7a111 Mon Sep 17 00:00:00 2001 From: ntziolis Date: Sat, 15 Feb 2020 13:50:37 +0100 Subject: [PATCH 03/15] fix(typings): use Parameter<> for setValue / patchValue + refactored base typing --- .../src/lib/ngx-sub-form-utils.ts | 36 +++++++++---------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/projects/ngx-sub-form/src/lib/ngx-sub-form-utils.ts b/projects/ngx-sub-form/src/lib/ngx-sub-form-utils.ts index 6e489a66..b54caa64 100644 --- a/projects/ngx-sub-form/src/lib/ngx-sub-form-utils.ts +++ b/projects/ngx-sub-form/src/lib/ngx-sub-form-utils.ts @@ -35,35 +35,33 @@ export type FormErrors = null | Partial< >; type Omit = Pick>; // can be removed when upgrading ts version -type UntypedControlBase = Omit< - TControl, - 'value' | 'valueChanges' | 'setValue' | 'patchValue' ->; -export type TypedAbstractControl = { +// defaulting to options in form control +type DefaultSetValueOptions = Parameters[1]; +type DefaultPatchValueOptions = Parameters[1]; + +type TypedControlBase = { value: TValue; valueChanges: Observable; setValue( value: TValue, - options?: { - onlySelf?: boolean; - emitEvent?: boolean; - emitModelToViewChange?: boolean; - emitViewToModelChange?: boolean; - }, + options?: TControl extends FormArray ? Parameters[1] : DefaultSetValueOptions, ): void; patchValue( value: Partial, - options?: { - onlySelf?: boolean; - emitEvent?: boolean; - emitModelToViewChange?: boolean; - emitViewToModelChange?: boolean; - }, + options?: TControl extends FormArray ? Parameters[1] : DefaultPatchValueOptions, ): void; -} & UntypedControlBase; +}; + +type UntypedControlBase = Omit< + TControl, + keyof TypedControlBase +>; + +export type TypedAbstractControl = TypedControlBase & + UntypedControlBase; -export type TypedFormArray = TypedAbstractControl & UntypedControlBase; +export type TypedFormArray = TypedControlBase & UntypedControlBase; export type KeysWithType = { [K in keyof T]: T[K] extends V ? K : never }[keyof T]; From ba3242b248b31152f603a6b1af138d84091d6030 Mon Sep 17 00:00:00 2001 From: ntziolis Date: Sat, 15 Feb 2020 15:38:38 +0100 Subject: [PATCH 04/15] chore(readme): added info about additional interfaces --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b0e277a9..e30e7d1a 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ If you want to see the demo in action, please visit [https://cloudnc.github.io/n - 2 classes for top level form components: `NgxRootFormComponent`, `NgxAutomaticRootFormComponent` - 2 classes for sub level form components: `NgxSubFormComponent`, `NgxSubFormRemapComponent` -- 3 interfaces: `Controls`, `ControlsNames`, `FormGroupOptions` +- 5 interfaces: `Controls`, `ControlsNames`, `FormGroupOptions`, `TypedAbstractControl`, `TypedFormArray` - 1 function: `subformComponentProviders` So there's actually nothing to setup (like a module), you can just use them directly. From f389439942e8f02bfd4c8d7017299c8a1e615a08 Mon Sep 17 00:00:00 2001 From: ntziolis Date: Sat, 15 Feb 2020 16:11:19 +0100 Subject: [PATCH 05/15] feat(typing): added control typings for form group --- .../ngx-sub-form/src/lib/ngx-sub-form-utils.ts | 13 +++++++++++-- .../src/lib/ngx-sub-form.component.ts | 15 ++++++++++----- .../ngx-sub-form/src/lib/ngx-sub-form.types.ts | 14 ++++++++------ 3 files changed, 29 insertions(+), 13 deletions(-) diff --git a/projects/ngx-sub-form/src/lib/ngx-sub-form-utils.ts b/projects/ngx-sub-form/src/lib/ngx-sub-form-utils.ts index b54caa64..97fe909a 100644 --- a/projects/ngx-sub-form/src/lib/ngx-sub-form-utils.ts +++ b/projects/ngx-sub-form/src/lib/ngx-sub-form-utils.ts @@ -6,6 +6,7 @@ import { FormControl, FormArray, AbstractControl, + FormGroup, } from '@angular/forms'; import { InjectionToken, Type, forwardRef, OnDestroy } from '@angular/core'; import { Observable, Subject, timer } from 'rxjs'; @@ -40,7 +41,7 @@ type Omit = Pick>; // can be removed when upgrading type DefaultSetValueOptions = Parameters[1]; type DefaultPatchValueOptions = Parameters[1]; -type TypedControlBase = { +export type TypedControlBase = { value: TValue; valueChanges: Observable; setValue( @@ -61,7 +62,15 @@ type UntypedControlBase = Omit< export type TypedAbstractControl = TypedControlBase & UntypedControlBase; -export type TypedFormArray = TypedControlBase & UntypedControlBase; +export type TypedFormArray = TypedControlBase & + Omit, 'controls'> & { + controls: TypedAbstractControl[]; + }; + +export type TypedFormGroup = TypedControlBase & + Omit, 'controls'> & { + controls: ControlsType; + }; export type KeysWithType = { [K in keyof T]: T[K] extends V ? K : never }[keyof T]; diff --git a/projects/ngx-sub-form/src/lib/ngx-sub-form.component.ts b/projects/ngx-sub-form/src/lib/ngx-sub-form.component.ts index 30e4cd4e..9ade6619 100644 --- a/projects/ngx-sub-form/src/lib/ngx-sub-form.component.ts +++ b/projects/ngx-sub-form/src/lib/ngx-sub-form.component.ts @@ -21,12 +21,17 @@ import { isNullOrUndefined, ControlsType, ArrayPropertyKey, + TypedAbstractControl, + TypedFormGroup, } from './ngx-sub-form-utils'; -import { FormGroupOptions, NgxFormWithArrayControls, OnFormUpdate, TypedFormGroup } from './ngx-sub-form.types'; +import { FormGroupOptions, NgxFormWithArrayControls, OnFormUpdate } from './ngx-sub-form.types'; -type MapControlFunction = (ctrl: AbstractControl, key: keyof FormInterface) => MapValue; +type MapControlFunction = ( + ctrl: TypedAbstractControl, + key: keyof FormInterface, +) => MapValue; type FilterControlFunction = ( - ctrl: AbstractControl, + ctrl: TypedAbstractControl, key: keyof FormInterface, isCtrlWithinFormArray: boolean, ) => boolean; @@ -145,7 +150,7 @@ export abstract class NgxSubFormComponent = this.formGroup.controls; + const formControls: ControlsType = this.formGroup.controls; const controls: Partial> = {}; @@ -352,7 +357,7 @@ export abstract class NgxSubFormComponent[] = formControlNames.map(key => - this.formGroup.controls[key].valueChanges.pipe( + (this.formGroup.controls[key] as unknown as AbstractControl).valueChanges.pipe( startWith(this.formGroup.controls[key].value), map(value => ({ key, value })), ), diff --git a/projects/ngx-sub-form/src/lib/ngx-sub-form.types.ts b/projects/ngx-sub-form/src/lib/ngx-sub-form.types.ts index 81c7661f..200c78af 100644 --- a/projects/ngx-sub-form/src/lib/ngx-sub-form.types.ts +++ b/projects/ngx-sub-form/src/lib/ngx-sub-form.types.ts @@ -1,6 +1,13 @@ import { FormControl, FormGroup, ValidationErrors } from '@angular/forms'; import { Observable } from 'rxjs'; -import { ArrayPropertyKey, ArrayPropertyValue, Controls, FormUpdate } from './ngx-sub-form-utils'; +import { + ArrayPropertyKey, + ArrayPropertyValue, + Controls, + FormUpdate, + ControlsType, + TypedFormGroup, +} from './ngx-sub-form-utils'; // @deprecated export interface OnFormUpdate { @@ -13,11 +20,6 @@ type Nullable = T | null; export type NullableObject = { [P in keyof T]: Nullable }; -export type TypedFormGroup = Omit & { - controls: Controls; - value: FormInterface; -}; - export type TypedValidatorFn = (formGroup: TypedFormGroup) => ValidationErrors | null; export type TypedAsyncValidatorFn = ( From 1f748533cbf4dbdcc8a69eb10327eeca2cfa8bb9 Mon Sep 17 00:00:00 2001 From: ntziolis Date: Sat, 15 Feb 2020 17:02:52 +0100 Subject: [PATCH 06/15] chore(formatting): ran prettier --- projects/ngx-sub-form/src/lib/ngx-sub-form.component.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/ngx-sub-form/src/lib/ngx-sub-form.component.ts b/projects/ngx-sub-form/src/lib/ngx-sub-form.component.ts index 9ade6619..accb894b 100644 --- a/projects/ngx-sub-form/src/lib/ngx-sub-form.component.ts +++ b/projects/ngx-sub-form/src/lib/ngx-sub-form.component.ts @@ -357,7 +357,7 @@ export abstract class NgxSubFormComponent[] = formControlNames.map(key => - (this.formGroup.controls[key] as unknown as AbstractControl).valueChanges.pipe( + ((this.formGroup.controls[key] as unknown) as AbstractControl).valueChanges.pipe( startWith(this.formGroup.controls[key].value), map(value => ({ key, value })), ), From 733f5c2eeff391f1fa6d3a749330af470c421a70 Mon Sep 17 00:00:00 2001 From: ntziolis Date: Sat, 15 Feb 2020 17:13:47 +0100 Subject: [PATCH 07/15] fix(lint): ignore interface-over-type-literal for TypedControlBase as all others are types as well --- projects/ngx-sub-form/src/lib/ngx-sub-form-utils.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/projects/ngx-sub-form/src/lib/ngx-sub-form-utils.ts b/projects/ngx-sub-form/src/lib/ngx-sub-form-utils.ts index 97fe909a..ff4b1f1c 100644 --- a/projects/ngx-sub-form/src/lib/ngx-sub-form-utils.ts +++ b/projects/ngx-sub-form/src/lib/ngx-sub-form-utils.ts @@ -41,6 +41,7 @@ type Omit = Pick>; // can be removed when upgrading type DefaultSetValueOptions = Parameters[1]; type DefaultPatchValueOptions = Parameters[1]; +// tslint:disable-next-line:interface-over-type-literal export type TypedControlBase = { value: TValue; valueChanges: Observable; From f26477514b2824a1c9b1c0af7f4403e78b0968b2 Mon Sep 17 00:00:00 2001 From: ntziolis Date: Mon, 24 Feb 2020 08:18:05 +0100 Subject: [PATCH 08/15] fix(typings): remove the use of omit to remove build errors when using Ivy #134 --- .../src/lib/ngx-sub-form-utils.ts | 58 ++++++++++--------- 1 file changed, 31 insertions(+), 27 deletions(-) diff --git a/projects/ngx-sub-form/src/lib/ngx-sub-form-utils.ts b/projects/ngx-sub-form/src/lib/ngx-sub-form-utils.ts index ff4b1f1c..ba1f46df 100644 --- a/projects/ngx-sub-form/src/lib/ngx-sub-form-utils.ts +++ b/projects/ngx-sub-form/src/lib/ngx-sub-form-utils.ts @@ -35,43 +35,47 @@ export type FormErrors = null | Partial< } >; -type Omit = Pick>; // can be removed when upgrading ts version - -// defaulting to options in form control -type DefaultSetValueOptions = Parameters[1]; -type DefaultPatchValueOptions = Parameters[1]; - -// tslint:disable-next-line:interface-over-type-literal -export type TypedControlBase = { +// using set/patch value options signature from form controls to allow typing without additional casting +export interface TypedAbstractControl extends AbstractControl { value: TValue; valueChanges: Observable; setValue( value: TValue, - options?: TControl extends FormArray ? Parameters[1] : DefaultSetValueOptions, + options?: Parameters[1], ): void; patchValue( value: Partial, - options?: TControl extends FormArray ? Parameters[1] : DefaultPatchValueOptions, + options?: Parameters[1], ): void; -}; - -type UntypedControlBase = Omit< - TControl, - keyof TypedControlBase ->; - -export type TypedAbstractControl = TypedControlBase & - UntypedControlBase; +} -export type TypedFormArray = TypedControlBase & - Omit, 'controls'> & { - controls: TypedAbstractControl[]; - }; +export interface TypedFormGroup extends FormGroup { + value: TValue; + valueChanges: Observable; + controls: ControlsType; + setValue( + value: TValue, + options?: Parameters[1], + ): void; + patchValue( + value: Partial, + options?: Parameters[1], + ): void; +} -export type TypedFormGroup = TypedControlBase & - Omit, 'controls'> & { - controls: ControlsType; - }; +export interface TypedFormArray extends FormArray { + value: TValue; + valueChanges: Observable; + controls: TypedAbstractControl[]; + setValue( + value: TValue[], + options?: Parameters[1], + ): void; + patchValue( + value: Partial, + options?: Parameters[1], + ): void; +} export type KeysWithType = { [K in keyof T]: T[K] extends V ? K : never }[keyof T]; From 4c9f247c18ec03416cfe10b5b569654c85b35729 Mon Sep 17 00:00:00 2001 From: ntziolis Date: Mon, 24 Feb 2020 08:34:16 +0100 Subject: [PATCH 09/15] fix(formatting): ran prettier:write --- .../src/lib/ngx-sub-form-utils.ts | 30 ++++--------------- 1 file changed, 6 insertions(+), 24 deletions(-) diff --git a/projects/ngx-sub-form/src/lib/ngx-sub-form-utils.ts b/projects/ngx-sub-form/src/lib/ngx-sub-form-utils.ts index ba1f46df..b0342dbb 100644 --- a/projects/ngx-sub-form/src/lib/ngx-sub-form-utils.ts +++ b/projects/ngx-sub-form/src/lib/ngx-sub-form-utils.ts @@ -39,42 +39,24 @@ export type FormErrors = null | Partial< export interface TypedAbstractControl extends AbstractControl { value: TValue; valueChanges: Observable; - setValue( - value: TValue, - options?: Parameters[1], - ): void; - patchValue( - value: Partial, - options?: Parameters[1], - ): void; + setValue(value: TValue, options?: Parameters[1]): void; + patchValue(value: Partial, options?: Parameters[1]): void; } export interface TypedFormGroup extends FormGroup { value: TValue; valueChanges: Observable; controls: ControlsType; - setValue( - value: TValue, - options?: Parameters[1], - ): void; - patchValue( - value: Partial, - options?: Parameters[1], - ): void; + setValue(value: TValue, options?: Parameters[1]): void; + patchValue(value: Partial, options?: Parameters[1]): void; } export interface TypedFormArray extends FormArray { value: TValue; valueChanges: Observable; controls: TypedAbstractControl[]; - setValue( - value: TValue[], - options?: Parameters[1], - ): void; - patchValue( - value: Partial, - options?: Parameters[1], - ): void; + setValue(value: TValue[], options?: Parameters[1]): void; + patchValue(value: Partial, options?: Parameters[1]): void; } export type KeysWithType = { [K in keyof T]: T[K] extends V ? K : never }[keyof T]; From 1ff3e3f8005729752a10a2b9836fb3d06aa28977 Mon Sep 17 00:00:00 2001 From: ntziolis Date: Mon, 24 Feb 2020 15:43:32 +0100 Subject: [PATCH 10/15] fix(typings): use Abstract control setValue/patchValue for TypedAbstractControl --- projects/ngx-sub-form/src/lib/ngx-sub-form-utils.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/projects/ngx-sub-form/src/lib/ngx-sub-form-utils.ts b/projects/ngx-sub-form/src/lib/ngx-sub-form-utils.ts index b0342dbb..f221bda8 100644 --- a/projects/ngx-sub-form/src/lib/ngx-sub-form-utils.ts +++ b/projects/ngx-sub-form/src/lib/ngx-sub-form-utils.ts @@ -39,8 +39,8 @@ export type FormErrors = null | Partial< export interface TypedAbstractControl extends AbstractControl { value: TValue; valueChanges: Observable; - setValue(value: TValue, options?: Parameters[1]): void; - patchValue(value: Partial, options?: Parameters[1]): void; + setValue(value: TValue, options?: Parameters[1]): void; + patchValue(value: Partial, options?: Parameters[1]): void; } export interface TypedFormGroup extends FormGroup { From c1afcdd92e7f055a98c099e9fb3e81bc5efe96a6 Mon Sep 17 00:00:00 2001 From: ntziolis Date: Mon, 24 Feb 2020 21:48:34 +0100 Subject: [PATCH 11/15] feat(typings): use optional typing for patch/setValue on TypedAbstractControl --- projects/ngx-sub-form/src/lib/ngx-sub-form-utils.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/projects/ngx-sub-form/src/lib/ngx-sub-form-utils.ts b/projects/ngx-sub-form/src/lib/ngx-sub-form-utils.ts index f221bda8..34734190 100644 --- a/projects/ngx-sub-form/src/lib/ngx-sub-form-utils.ts +++ b/projects/ngx-sub-form/src/lib/ngx-sub-form-utils.ts @@ -39,8 +39,14 @@ export type FormErrors = null | Partial< export interface TypedAbstractControl extends AbstractControl { value: TValue; valueChanges: Observable; - setValue(value: TValue, options?: Parameters[1]): void; - patchValue(value: Partial, options?: Parameters[1]): void; + setValue( + value: TValue, + options?: Parameters[1] | Parameters[1], + ): void; + patchValue( + value: Partial, + options?: Parameters[1] | Parameters[1], + ): void; } export interface TypedFormGroup extends FormGroup { From a658d31be104369455bded0b017eb2354d695cf8 Mon Sep 17 00:00:00 2001 From: ntziolis Date: Tue, 25 Feb 2020 07:22:37 +0100 Subject: [PATCH 12/15] feat(typings): updated typings for ControlType to an intersection for non arrays --- .../src/lib/ngx-sub-form-utils.ts | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/projects/ngx-sub-form/src/lib/ngx-sub-form-utils.ts b/projects/ngx-sub-form/src/lib/ngx-sub-form-utils.ts index 34734190..4ae33606 100644 --- a/projects/ngx-sub-form/src/lib/ngx-sub-form-utils.ts +++ b/projects/ngx-sub-form/src/lib/ngx-sub-form-utils.ts @@ -21,7 +21,7 @@ export type ControlsNames = { [K in keyof T]-?: K }; export type ControlMap = { [K in keyof T]-?: V }; export type ControlsType = { - [K in keyof T]-?: T[K] extends any[] ? TypedFormArray : TypedAbstractControl; + [K in keyof T]-?: T[K] extends any[] ? TypedFormArray : TypedFormControl | TypedFormGroup; }; export type FormErrorsType = { [K in keyof T]-?: T[K] extends any[] ? (null | ValidationErrors)[] : ValidationErrors; @@ -39,14 +39,8 @@ export type FormErrors = null | Partial< export interface TypedAbstractControl extends AbstractControl { value: TValue; valueChanges: Observable; - setValue( - value: TValue, - options?: Parameters[1] | Parameters[1], - ): void; - patchValue( - value: Partial, - options?: Parameters[1] | Parameters[1], - ): void; + setValue(value: TValue, options?: Parameters[1]): void; + patchValue(value: Partial, options?: Parameters[1]): void; } export interface TypedFormGroup extends FormGroup { @@ -65,6 +59,13 @@ export interface TypedFormArray extends FormArray { patchValue(value: Partial, options?: Parameters[1]): void; } +export interface TypedFormControl extends FormGroup { + value: TValue; + valueChanges: Observable; + setValue(value: TValue, options?: Parameters[1]): void; + patchValue(value: Partial, options?: Parameters[1]): void; +} + export type KeysWithType = { [K in keyof T]: T[K] extends V ? K : never }[keyof T]; export type ArrayPropertyKey = KeysWithType>; From 7dc81c440054cd4aec1014c916b004453db9c30b Mon Sep 17 00:00:00 2001 From: ntziolis Date: Tue, 25 Feb 2020 07:53:26 +0100 Subject: [PATCH 13/15] chore(utils): cleanup --- projects/ngx-sub-form/src/lib/ngx-sub-form-utils.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/projects/ngx-sub-form/src/lib/ngx-sub-form-utils.ts b/projects/ngx-sub-form/src/lib/ngx-sub-form-utils.ts index 4ae33606..7b35aa35 100644 --- a/projects/ngx-sub-form/src/lib/ngx-sub-form-utils.ts +++ b/projects/ngx-sub-form/src/lib/ngx-sub-form-utils.ts @@ -23,6 +23,7 @@ export type ControlMap = { [K in keyof T]-?: V }; export type ControlsType = { [K in keyof T]-?: T[K] extends any[] ? TypedFormArray : TypedFormControl | TypedFormGroup; }; + export type FormErrorsType = { [K in keyof T]-?: T[K] extends any[] ? (null | ValidationErrors)[] : ValidationErrors; }; From 338a9b8c48043bebe0060cf335523042a9750a4f Mon Sep 17 00:00:00 2001 From: ntziolis Date: Wed, 26 Feb 2020 08:23:47 +0100 Subject: [PATCH 14/15] feat(readme): updated list of interfaces --- README.md | 2 +- projects/ngx-sub-form/src/lib/ngx-sub-form.types.ts | 8 +------- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 537ea5dc..ff5e90b0 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,7 @@ If you want to see the demo in action, please visit [https://cloudnc.github.io/n - 2 classes for top level form components: `NgxRootFormComponent`, `NgxAutomaticRootFormComponent` - 2 classes for sub level form components: `NgxSubFormComponent`, `NgxSubFormRemapComponent` -- 5 interfaces: `Controls`, `ControlsNames`, `FormGroupOptions`, `TypedAbstractControl`, `TypedFormArray` +- 7 interfaces: `Controls`, `ControlsNames`, `FormGroupOptions`, `TypedFormGroup`, `TypedFormArray`, `TypedFormControl`, `TypedAbstractControl` - 1 function: `subformComponentProviders` So there's actually nothing to setup (like a module), you can just use them directly. diff --git a/projects/ngx-sub-form/src/lib/ngx-sub-form.types.ts b/projects/ngx-sub-form/src/lib/ngx-sub-form.types.ts index e459ae07..8f881c3d 100644 --- a/projects/ngx-sub-form/src/lib/ngx-sub-form.types.ts +++ b/projects/ngx-sub-form/src/lib/ngx-sub-form.types.ts @@ -1,12 +1,6 @@ import { FormControl, FormGroup, ValidationErrors } from '@angular/forms'; import { Observable } from 'rxjs'; -import { - ArrayPropertyKey, - ArrayPropertyValue, - Controls, - FormUpdate, - TypedFormGroup, -} from './ngx-sub-form-utils'; +import { ArrayPropertyKey, ArrayPropertyValue, Controls, FormUpdate, TypedFormGroup } from './ngx-sub-form-utils'; // @deprecated export interface OnFormUpdate { From 1472ab01ccd2203a2e3b5a638a5c2239dbb99e88 Mon Sep 17 00:00:00 2001 From: ntziolis Date: Wed, 26 Feb 2020 08:26:32 +0100 Subject: [PATCH 15/15] fix(typed-form-array): set/patchValue now use TValue directly as it extends any[] --- projects/ngx-sub-form/src/lib/ngx-sub-form-utils.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/projects/ngx-sub-form/src/lib/ngx-sub-form-utils.ts b/projects/ngx-sub-form/src/lib/ngx-sub-form-utils.ts index 7b35aa35..8d5c116c 100644 --- a/projects/ngx-sub-form/src/lib/ngx-sub-form-utils.ts +++ b/projects/ngx-sub-form/src/lib/ngx-sub-form-utils.ts @@ -52,12 +52,12 @@ export interface TypedFormGroup extends FormGroup { patchValue(value: Partial, options?: Parameters[1]): void; } -export interface TypedFormArray extends FormArray { +export interface TypedFormArray extends FormArray { value: TValue; valueChanges: Observable; controls: TypedAbstractControl[]; - setValue(value: TValue[], options?: Parameters[1]): void; - patchValue(value: Partial, options?: Parameters[1]): void; + setValue(value: TValue, options?: Parameters[1]): void; + patchValue(value: TValue, options?: Parameters[1]): void; } export interface TypedFormControl extends FormGroup {