Skip to content

Commit 05ad0a8

Browse files
authored
Merge pull request #145 from cloudnc/fix/ivy-compilation
fix(Ivy): Fix TypedFormGroup<T> not being assignable to FormGroup
2 parents 1ba8842 + 4381a42 commit 05ad0a8

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { FormControl, FormGroup } from '@angular/forms';
2+
import { TypedFormGroup } from 'ngx-sub-form';
3+
4+
describe(`TypedFormGroup`, () => {
5+
it(`should be assignable to the base @angular/forms FormGroup`, () => {
6+
let formGroup: FormGroup;
7+
8+
const typedFormGroup = new FormGroup({ foo: new FormControl() }) as TypedFormGroup<{ foo: true }>;
9+
10+
formGroup = typedFormGroup;
11+
12+
expect(true).toBe(true); // this is a type-only test, if the type breaks the test will not compile
13+
});
14+
});

projects/ngx-sub-form/src/lib/ngx-sub-form.types.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,14 @@ export interface OnFormUpdate<FormInterface> {
88
onFormUpdate?: (formUpdate: FormUpdate<FormInterface>) => void;
99
}
1010

11-
type Omit<T, K> = Pick<T, Exclude<keyof T, K>>;
1211
type Nullable<T> = T | null;
1312

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

16-
export type TypedFormGroup<FormInterface> = Omit<FormGroup, 'controls' | 'value'> & {
15+
export interface TypedFormGroup<FormInterface> extends FormGroup {
1716
controls: Controls<FormInterface>;
1817
value: FormInterface;
19-
};
18+
}
2019

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

0 commit comments

Comments
 (0)