Skip to content

Commit

Permalink
fix(Ivy): Fix TypedFormGroup<T> not being assignable to FormGroup
Browse files Browse the repository at this point in the history
Fixes #134
  • Loading branch information
zak-cloudnc committed Feb 23, 2020
1 parent 1ba8842 commit 4381a42
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
14 changes: 14 additions & 0 deletions projects/ngx-sub-form/src/lib/ngx-sub-form.types.spec.ts
Original file line number Diff line number Diff line change
@@ -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
});
});
5 changes: 2 additions & 3 deletions projects/ngx-sub-form/src/lib/ngx-sub-form.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@ export interface OnFormUpdate<FormInterface> {
onFormUpdate?: (formUpdate: FormUpdate<FormInterface>) => void;
}

type Omit<T, K> = Pick<T, Exclude<keyof T, K>>;
type Nullable<T> = T | null;

export type NullableObject<T> = { [P in keyof T]: Nullable<T[P]> };

export type TypedFormGroup<FormInterface> = Omit<FormGroup, 'controls' | 'value'> & {
export interface TypedFormGroup<FormInterface> extends FormGroup {
controls: Controls<FormInterface>;
value: FormInterface;
};
}

export type TypedValidatorFn<T> = (formGroup: TypedFormGroup<T>) => ValidationErrors | null;

Expand Down

0 comments on commit 4381a42

Please sign in to comment.