Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Ivy): Fix TypedFormGroup<T> not being assignable to FormGroup #145

Merged
merged 1 commit into from
Feb 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {
maxime1992 marked this conversation as resolved.
Show resolved Hide resolved
controls: Controls<FormInterface>;
value: FormInterface;
};
}

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

Expand Down