Skip to content

Commit 00885ae

Browse files
committed
fix: fix type errors on TypeScript 4.8+
1 parent b554b5b commit 00885ae

25 files changed

+62
-56
lines changed

src/actions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ export type Actions<TValue> =
246246
| UnfocusAction
247247
| MarkAsSubmittedAction
248248
| MarkAsUnsubmittedAction
249-
| AddGroupControlAction<TValue>
249+
| (TValue extends KeyValue ? AddGroupControlAction<TValue> : never)
250250
| RemoveGroupControlAction<TValue>
251251
| AddArrayControlAction<any>
252252
| RemoveArrayControlAction

src/array/reducer/move-control.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export function moveControlReducer<TValue>(
5151

5252
let controls = move(state.controls, fromIndex, toIndex);
5353

54-
controls = controls.map((c, i) => updateIdRecursive(c, `${state.id}.${i}`));
54+
controls = controls.map((c, i) => updateIdRecursive<any>(c, `${state.id}.${i}`));
5555

5656
return computeArrayState(
5757
state.id,

src/array/reducer/swap-control.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export function swapControlReducer<TValue>(
3636
}
3737

3838
let controls = swapArrayValues(state.controls, fromIndex, toIndex);
39-
controls = controls.map((c, i) => (i >= fromIndex || i >= toIndex) ? updateIdRecursive(c, `${state.id}.${i}`) : c);
39+
controls = controls.map((c, i) => (i >= fromIndex || i >= toIndex) ? updateIdRecursive<any>(c, `${state.id}.${i}`) : c);
4040

4141
return computeArrayState(
4242
state.id,

src/boxing.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export function box<T>(value: T): Boxed<T> {
3232
}
3333

3434
export function unbox<T>(value: T): Unboxed<T> {
35-
if (['string', 'boolean', 'number', 'undefined'].indexOf(typeof value) >= 0 || value === null) {
35+
if (['string', 'boolean', 'number', 'undefined'].indexOf(typeof value) >= 0 || value === null || value === undefined) {
3636
return value as unknown as Unboxed<T>;
3737
}
3838

src/group/directive.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Directive, HostListener, Inject, Input, OnInit, Optional } from '@angul
22
import { ActionsSubject } from '@ngrx/store';
33

44
import { Actions, MarkAsSubmittedAction } from '../actions';
5-
import { FormGroupState } from '../state';
5+
import { FormGroupState, KeyValue } from '../state';
66

77
// this interface just exists to prevent a direct reference to
88
// `Event` in our code, which otherwise causes issues in NativeScript
@@ -13,7 +13,7 @@ interface CustomEvent extends Event { }
1313
// tslint:disable-next-line:directive-selector
1414
selector: 'form:not([ngrxFormsAction])[ngrxFormState]',
1515
})
16-
export class NgrxFormDirective<TStateValue> implements OnInit {
16+
export class NgrxFormDirective<TStateValue extends KeyValue> implements OnInit {
1717
// tslint:disable-next-line:no-input-rename
1818
@Input('ngrxFormState') state: FormGroupState<TStateValue>;
1919

src/group/local-state-directive.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import { Directive, EventEmitter, Output } from '@angular/core';
22

33
import { Actions } from '../actions';
4+
import { KeyValue } from '../state';
45
import { NgrxFormDirective } from './directive';
56

67
@Directive({
78
// tslint:disable-next-line:directive-selector
89
selector: 'form[ngrxFormState][ngrxFormsAction]',
910
})
10-
export class NgrxLocalFormDirective<TStateValue> extends NgrxFormDirective<TStateValue> {
11+
export class NgrxLocalFormDirective<TStateValue extends KeyValue> extends NgrxFormDirective<TStateValue> {
1112

1213
@Output() ngrxFormsAction = new EventEmitter<Actions<TStateValue>>();
1314

src/group/reducer/add-control.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ export function addControlReducer<TValue extends KeyValue>(
1515
}
1616

1717
if (state.controls.hasOwnProperty(action.name)) {
18-
throw new Error(`Group '${state.id}' already has child control '${action.name}'!`); // `;
18+
throw new Error(`Group '${state.id}' already has child control '${action.name as string}'!`); // `;
1919
}
2020

2121
const controls = Object.assign({}, state.controls, {
22-
[action.name]: createChildState(`${state.id}.${action.name}`, action.value),
22+
[action.name]: createChildState(`${state.id}.${action.name as string}`, action.value),
2323
});
2424

2525
return computeGroupState(

src/group/reducer/remove-control.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export function removeControlReducer<TValue extends KeyValue>(
1515
}
1616

1717
if (!state.controls.hasOwnProperty(action.name)) {
18-
throw new Error(`Group '${state.id}' does not have child control '${action.name}'!`); // `;
18+
throw new Error(`Group '${state.id}' does not have child control '${action.name as string}'!`); // `;
1919
}
2020

2121
const controls = Object.assign({}, state.controls);

src/group/reducer/set-value.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Actions, SetValueAction } from '../../actions';
22
import { formStateReducer } from '../../reducer';
3-
import { computeGroupState, createChildState, FormGroupControls, FormGroupState, KeyValue } from '../../state';
3+
import { AbstractControlState, computeGroupState, createChildState, FormGroupControls, FormGroupState, KeyValue } from '../../state';
44
import { childReducer } from './util';
55

66
export function setValueReducer<TValue extends KeyValue>(
@@ -31,7 +31,7 @@ export function setValueReducer<TValue extends KeyValue>(
3131
if (!state.controls[key]) {
3232
Object.assign(c, { [key]: createChildState<TValue[string]>(`${state.id}.${key}`, value[key]) });
3333
} else {
34-
Object.assign(c, { [key]: formStateReducer(state.controls[key], new SetValueAction(state.controls[key].id, value[key])) });
34+
Object.assign(c, { [key]: formStateReducer(state.controls[key], new SetValueAction((state.controls[key] as AbstractControlState<unknown>).id, value[key])) });
3535
}
3636
return c;
3737
}, {} as FormGroupControls<TValue>);

src/group/reducer/util.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Actions } from '../../actions';
22
import { formStateReducer } from '../../reducer';
3-
import { computeGroupState, FormGroupControls, FormGroupState, FormState, KeyValue } from '../../state';
3+
import { AbstractControlState, computeGroupState, FormGroupControls, FormGroupState, FormState, KeyValue } from '../../state';
44

55
export function dispatchActionPerChild<TValue extends KeyValue>(
66
controls: FormGroupControls<TValue>,
@@ -9,7 +9,7 @@ export function dispatchActionPerChild<TValue extends KeyValue>(
99
let hasChanged = false;
1010
const newControls = Object.keys(controls)
1111
.reduce((c, key) => {
12-
Object.assign(c, { [key]: formStateReducer(controls[key], actionCreator(controls[key].id)) });
12+
Object.assign(c, { [key]: formStateReducer(controls[key], actionCreator((controls[key] as AbstractControlState<unknown>).id)) });
1313
hasChanged = hasChanged || c[key] !== controls[key];
1414
return c;
1515
}, {} as FormGroupControls<TValue>);

0 commit comments

Comments
 (0)