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;