Skip to content

Commit

Permalink
fix: handle 'any' values properly in 'patchValue' (#59)
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelss95 authored Nov 29, 2020
1 parent ceede84 commit 0ccdd2e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion projects/ngneat/reactive-forms/src/lib/formGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ export class FormGroup<T extends Obj = any, E extends object = any> extends NgFo
}

private restore(key: string, manager: PersistManager<T>, arrControlFactory: ControlFactoryMap<T>): Observable<T> {
return wrapIntoObservable<T>(manager.getValue(key)).pipe(
return wrapIntoObservable(manager.getValue(key)).pipe(
take(1),
tap(value => {
if (!value) return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,19 @@ describe('with generic', () => {
control.setValidators([required, pattern]);
});

test('control patchValue should accept any', () => {
const control = new FormGroup<NestedForm>({
a: new FormControl(22),
b: new FormControl({
a: '',
c: [3]
}),
d: new FormControl<boolean>(),
e: new FormControl('')
});
expectTypeOf(control.patchValue(of({ e: 2 }))).toEqualTypeOf(new Subscription());
});

test('control patchValue should accept nested partials', () => {
const control = new FormGroup<NestedForm>({
a: new FormControl(22),
Expand Down
5 changes: 1 addition & 4 deletions projects/ngneat/reactive-forms/src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,7 @@ export interface NgValidatorsErrors {

export type BoxedValue<T> = { value: T; disabled?: boolean };
export type OrBoxedValue<T> = T | BoxedValue<T>;
export type DeepPartial<T> = {
[P in keyof T]?: DeepPartial<T[P]>;
};

export type DeepPartial<T> = { [K in keyof T]?: T[K] extends object ? DeepPartial<T[K]> : T[K] };
export type Obj = { [key: string]: any };
type ArrayType<T> = T extends Array<infer R> ? R : any;

Expand Down

0 comments on commit 0ccdd2e

Please sign in to comment.