From 4381a425439d6dd29c86b7974a2d30470156e905 Mon Sep 17 00:00:00 2001 From: Zak Henry Date: Sun, 23 Feb 2020 23:08:10 +0000 Subject: [PATCH] fix(Ivy): Fix TypedFormGroup not being assignable to FormGroup Fixes #134 --- .../src/lib/ngx-sub-form.types.spec.ts | 14 ++++++++++++++ .../ngx-sub-form/src/lib/ngx-sub-form.types.ts | 5 ++--- 2 files changed, 16 insertions(+), 3 deletions(-) create mode 100644 projects/ngx-sub-form/src/lib/ngx-sub-form.types.spec.ts diff --git a/projects/ngx-sub-form/src/lib/ngx-sub-form.types.spec.ts b/projects/ngx-sub-form/src/lib/ngx-sub-form.types.spec.ts new file mode 100644 index 00000000..10ea7fda --- /dev/null +++ b/projects/ngx-sub-form/src/lib/ngx-sub-form.types.spec.ts @@ -0,0 +1,14 @@ +import { FormControl, FormGroup } from '@angular/forms'; +import { TypedFormGroup } from 'ngx-sub-form'; + +describe(`TypedFormGroup`, () => { + it(`should be assignable to the base @angular/forms FormGroup`, () => { + let formGroup: FormGroup; + + const typedFormGroup = new FormGroup({ foo: new FormControl() }) as TypedFormGroup<{ foo: true }>; + + formGroup = typedFormGroup; + + expect(true).toBe(true); // this is a type-only test, if the type breaks the test will not compile + }); +}); 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..41882f49 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 @@ -8,15 +8,14 @@ export interface OnFormUpdate { onFormUpdate?: (formUpdate: FormUpdate) => void; } -type Omit = Pick>; type Nullable = T | null; export type NullableObject = { [P in keyof T]: Nullable }; -export type TypedFormGroup = Omit & { +export interface TypedFormGroup extends FormGroup { controls: Controls; value: FormInterface; -}; +} export type TypedValidatorFn = (formGroup: TypedFormGroup) => ValidationErrors | null;