Skip to content

Commit

Permalink
Merge pull request #145 from cloudnc/fix/ivy-compilation
Browse files Browse the repository at this point in the history
fix(Ivy): Fix TypedFormGroup<T> not being assignable to FormGroup
  • Loading branch information
zak-cloudnc authored Feb 25, 2020
2 parents 1ba8842 + 4381a42 commit 05ad0a8
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 05ad0a8

Please sign in to comment.