Skip to content

Commit 1e2d72b

Browse files
SethDavenportsmithad15
authored andcommitted
Turn tsconfig settings to 11 (angular-redux#34)
* `"strict": true,` * `"noUnusedLocals": true,` * `"noUnusedParameters": true,` * `"forceConsistentCasingInFileNames": true,` Also updated to typescript 2.4.1. Also simplify the implementation of composeReducers. The composed reducer will assemble initial state automatically during Redux initialization; we don't need to do all that state manipulation manually. Fixes angular-redux#26
1 parent f9bcb12 commit 1e2d72b

13 files changed

+61
-74
lines changed

packages/form/.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,5 @@ dist
4848

4949
source/*ngfactory.ts
5050
source/*ngsummary.json
51+
52+
*.tgz

packages/form/.npmignore

+1
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ coverage/
88
.vscode/
99
docs/
1010
webpack/
11+
*.tgz

packages/form/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@angular-redux/form",
3-
"version": "6.5.1",
3+
"version": "6.5.2",
44
"description": "Build Angular 2+ forms with Redux",
55
"dependencies": {
66
"immutable": "^3.8.1"
@@ -42,7 +42,7 @@
4242
"reflect-metadata": "^0.1.3",
4343
"rimraf": "^2.5.4",
4444
"rxjs": "^5.0.1",
45-
"typescript": "^2.1.0",
45+
"typescript": "^2.4.1",
4646
"webpack": "^2.1.0-beta.25",
4747
"zone.js": "^0.8.4"
4848
},
+3-27
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,6 @@
11
import {Reducer, Action} from 'redux';
22

3-
import {State} from './state';
4-
53
export const composeReducers =
6-
<State>(...reducers: Reducer<State>[]): Reducer<State> => {
7-
// Pull from each reducer its initial state value, from the default
8-
// value of the `state' argument. So we are provided with {initialState},
9-
// and then with the individual initial states of each reducer. We
10-
// compose all these states together to produce a true 'initial state'
11-
// for our composed reducer.
12-
let state: State = null;
13-
14-
for (const reducer of reducers) {
15-
const result = reducer.apply(null, [undefined, {type: ''}]);
16-
if (result === undefined) {
17-
continue;
18-
}
19-
20-
if (state == null) {
21-
state = result;
22-
}
23-
else {
24-
state = State.inspect(state).merge(null, result);
25-
}
26-
}
27-
28-
return (s: State = state, action: Action) =>
29-
reducers.reduce((st, reducer) => reducer(st, action), s);
30-
};
4+
<State>(...reducers: Reducer<State>[]): Reducer<State> =>
5+
(s: State, action: Action) =>
6+
reducers.reduce((st, reducer) => reducer(st, action), s);

packages/form/source/connect-array.ts

+10-10
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ import {controlPath, selectValueAccessor} from './shims';
4343

4444
export class ConnectArrayTemplate {
4545
constructor(
46-
public $implicit,
46+
public $implicit: any,
4747
public index: number,
48-
public item
48+
public item: any
4949
) {}
5050
}
5151

@@ -85,7 +85,7 @@ export class ConnectArray extends ControlContainer implements OnInit {
8585
}
8686

8787
@Input()
88-
set connectArrayOf(collection) {
88+
set connectArrayOf(collection: any) {
8989
this.key = collection;
9090

9191
this.resetState(this.store.getState());
@@ -131,7 +131,7 @@ export class ConnectArray extends ControlContainer implements OnInit {
131131
this.formDirective.form.removeControl(this.key);
132132
}
133133

134-
private resetState(state) {
134+
private resetState(state: any) {
135135
if (this.key == null || this.key.length === 0) {
136136
return; // no state to retreive if no key is set
137137
}
@@ -174,7 +174,7 @@ export class ConnectArray extends ControlContainer implements OnInit {
174174
}
175175
}
176176

177-
private registerInternals(array) {
177+
private registerInternals(array: any) {
178178
array.registerControl = () => {};
179179
array.registerOnChange = () => {};
180180

@@ -188,7 +188,7 @@ export class ConnectArray extends ControlContainer implements OnInit {
188188
});
189189
}
190190

191-
private patchDescendantControls(viewRef) {
191+
private patchDescendantControls(viewRef: any) {
192192
const groups = Object.keys(viewRef._view)
193193
.map(k => viewRef._view[k])
194194
.filter(c => c instanceof NgModelGroup);
@@ -205,7 +205,7 @@ export class ConnectArray extends ControlContainer implements OnInit {
205205
});
206206
}
207207

208-
private transform(parent: FormGroup | FormArray, reference): AbstractControl {
208+
private transform(parent: FormGroup | FormArray, reference: any): AbstractControl {
209209
const emptyControl = () => {
210210
const control = new FormControl(null);
211211
control.setParent(parent);
@@ -227,7 +227,7 @@ export class ConnectArray extends ControlContainer implements OnInit {
227227
return emptyControl();
228228
}
229229

230-
const iterate = (iterable): FormArray => {
230+
const iterate = (iterable: any): FormArray => {
231231
const array = new FormArray([]);
232232

233233
this.registerInternals(array);
@@ -246,7 +246,7 @@ export class ConnectArray extends ControlContainer implements OnInit {
246246
return array;
247247
}
248248

249-
const associate = (value): FormGroup => {
249+
const associate = (value: any): FormGroup => {
250250
const group = new FormGroup({});
251251
group.setParent(parent);
252252

@@ -280,7 +280,7 @@ export class ConnectArray extends ControlContainer implements OnInit {
280280

281281
private simpleAccessor() {
282282
return {
283-
writeValue: value => this.control.setValue(value),
283+
writeValue: (value: any) => this.control.setValue(value),
284284
registerOnChange() {},
285285
registerOnTouched() {}
286286
};

packages/form/source/connect-base.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export class ConnectBase {
2929

3030
private formSubscription: Subscription;
3131
protected store: FormStore;
32-
protected form;
32+
protected form: any;
3333

3434
public get path(): Array<string> {
3535
const path = typeof this.connect === 'function'
@@ -68,12 +68,14 @@ export class ConnectBase {
6868
this.stateSubscription = this.store.subscribe(() => this.resetState());
6969

7070
Promise.resolve().then(() => {
71-
this.formSubscription = (<any>this.form.valueChanges).debounceTime(0).subscribe(values => this.publish(values));
71+
this.formSubscription = (<any>this.form.valueChanges)
72+
.debounceTime(0)
73+
.subscribe((values: any) => this.publish(values));
7274
});
7375
});
7476
}
7577

76-
private descendants(path: Array<string>, formElement): Array<ControlPair> {
78+
private descendants(path: Array<string>, formElement: any): Array<ControlPair> {
7779
const pairs = new Array<ControlPair>();
7880

7981
if (formElement instanceof FormArray) {
@@ -122,7 +124,7 @@ export class ConnectBase {
122124
});
123125
}
124126

125-
private publish(value) {
127+
private publish(value: any) {
126128
this.store.valueChanged(this.path, this.form, value);
127129
}
128130

packages/form/source/connect-reactive.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {ConnectBase} from './connect-base';
1010
// For reactive forms (without implicit NgForm)
1111
@Directive({ selector: 'form[connect][formGroup]' })
1212
export class ReactiveConnect extends ConnectBase {
13-
@Input('formGroup') form;
13+
@Input('formGroup') form: any;
1414

1515
constructor(
1616
protected store: FormStore

packages/form/source/form-reducer.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {FORM_CHANGED} from './form-store';
77
import {State} from './state';
88

99
export const defaultFormReducer = <RootState>(initialState?: RootState | Iterable.Keyed<string, any>) => {
10-
const reducer = (state: RootState | Iterable.Keyed<string, any> = initialState, action: Action & {payload?}) => {
10+
const reducer = (state: RootState | Iterable.Keyed<string, any> | undefined = initialState, action: Action & {payload?: any}) => {
1111
switch (action.type) {
1212
case FORM_CHANGED:
1313
return State.assign(

packages/form/source/form-store.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {Action, Unsubscribe} from 'redux';
88

99
export interface AbstractStore<RootState> {
1010
/// Dispatch an action
11-
dispatch(action: Action & {payload}): void;
11+
dispatch(action: Action & {payload: any}): void;
1212

1313
/// Retrieve the current application state
1414
getState(): RootState;
@@ -34,7 +34,7 @@ export class FormStore {
3434
return this.store.getState();
3535
}
3636

37-
subscribe(fn: (state) => void): Unsubscribe {
37+
subscribe(fn: (state: any) => void): Unsubscribe {
3838
return this.store.subscribe(() => fn(this.getState()));
3939
}
4040

packages/form/source/shims.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ export function controlPath(name: string, parent: ControlContainer): string[] {
1414
}
1515

1616
export function selectValueAccessor(
17-
dir: NgControl, valueAccessors: ControlValueAccessor[]): ControlValueAccessor {
17+
dir: NgControl, valueAccessors: ControlValueAccessor[]): ControlValueAccessor | null {
1818
if (!valueAccessors) return null;
1919

20-
let defaultAccessor: ControlValueAccessor;
21-
let builtinAccessor: ControlValueAccessor;
22-
let customAccessor: ControlValueAccessor;
20+
let defaultAccessor: ControlValueAccessor | null = null;
21+
let builtinAccessor: ControlValueAccessor | null = null;
22+
let customAccessor: ControlValueAccessor | null = null;
2323
valueAccessors.forEach((v: ControlValueAccessor) => {
2424
if (v.constructor === DefaultValueAccessor) {
2525
defaultAccessor = v;

packages/form/source/state.ts

+19-19
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ export interface Operations<T> {
77
clone(): T;
88

99
/// Clone and merge
10-
merge(key: number | string, value: T);
10+
merge(key: number | string | null, value: T): any;
1111

1212
/// Clone the object and update a specific key inside of it
13-
update(key: number | string, value: T);
13+
update(key: number | string | null, value: T): any;
1414
}
1515

1616
export interface TraverseCallback {
17-
(parent, key: number | string, remainingPath: string[], value?);
17+
(parent: any, key: number | string, remainingPath: string[], value?: any): any;
1818
}
1919

2020
export abstract class State {
@@ -37,7 +37,7 @@ export abstract class State {
3737
deepValue = (<Map<string, any>> <any> deepValue).get(k);
3838
}
3939
else {
40-
deepValue = deepValue[k];
40+
deepValue = (deepValue as any)[k];
4141
}
4242

4343
if (typeof fn === 'function') {
@@ -64,7 +64,7 @@ export abstract class State {
6464
return State.traverse(state, path);
6565
}
6666

67-
static assign<State>(state: State, path: string[], value?) {
67+
static assign<State>(state: State, path: string[], value?: any) {
6868
const operations = State.inspect(state);
6969

7070
if (path.length === 0) {
@@ -117,7 +117,7 @@ export abstract class State {
117117
}
118118

119119
static inspect<K>(object: K): Operations<K> {
120-
const metaOperations = (update, merge, clone?) => {
120+
const metaOperations = (update: Function, merge: Function, clone?: Function) => {
121121
const operations = {
122122
/// Clone the object (shallow)
123123
clone: typeof clone === 'function'
@@ -130,7 +130,7 @@ export abstract class State {
130130
/// Merge existing values with new values
131131
merge: (key: string, value: K) => {
132132
const cloned = operations.clone();
133-
return merge(cloned, key, value, v => update(cloned, key, v));
133+
return merge(cloned, key, value, (v: any) => update(cloned, key, v));
134134
}
135135
};
136136

@@ -140,7 +140,7 @@ export abstract class State {
140140
if (Iterable.isIterable(object)) {
141141
return metaOperations(
142142
// Replace
143-
(parent, key: number | string, value: K) => {
143+
(parent: any, key: number | string, value: K) => {
144144
if (key != null) {
145145
return parent.set(key, value);
146146
}
@@ -149,7 +149,7 @@ export abstract class State {
149149
}
150150
},
151151
// Merge
152-
(parent, key: number | string | string[], value: K) => {
152+
(parent: any, key: number | string | string[], value: K) => {
153153
if (key) {
154154
return parent.mergeDeepIn(Array.isArray(key) ? key : [key], value);
155155
}
@@ -166,7 +166,7 @@ export abstract class State {
166166
else if (Array.isArray(object)) {
167167
return metaOperations(
168168
// Replace array contents
169-
(parent, key: number, value: K) => {
169+
(parent: any, key: number, value: K) => {
170170
if (key != null) {
171171
parent[key] = value;
172172
}
@@ -177,7 +177,7 @@ export abstract class State {
177177
},
178178

179179
// Merge
180-
(parent, _, value: K, setter: (v: K) => K) => {
180+
(parent: any, _: any, value: K, setter: (v: K) => K) => {
181181
setter(parent.concat(value));
182182
return parent;
183183
},
@@ -189,7 +189,7 @@ export abstract class State {
189189
else if (object instanceof Map) {
190190
return metaOperations(
191191
// Update map key
192-
(parent, key: number | string, value: K) => {
192+
(parent: any, key: number | string, value: K) => {
193193
if (key != null) {
194194
return parent.set(key, value);
195195
}
@@ -202,7 +202,7 @@ export abstract class State {
202202
},
203203

204204
// Merge
205-
(parent: Map<string, any>, _, value: K) => {
205+
(parent: Map<string, any>, _: any, value: K) => {
206206
const m = new Map<string, any>(<any> value);
207207
m.forEach((value, key) => parent.set(key, value));
208208
return parent;
@@ -217,7 +217,7 @@ export abstract class State {
217217
else if (object instanceof WeakSet || object instanceof Set) {
218218
return metaOperations(
219219
// Update element at index in set
220-
(parent, key: number, value: K) => {
220+
(parent: any, key: number, value: K) => {
221221
if (key != null) {
222222
return parent.set(key, value);
223223
}
@@ -230,7 +230,7 @@ export abstract class State {
230230
},
231231

232232
// Merge
233-
(parent: Set<any>, _, value) => {
233+
(parent: Set<any>, _: any, value: any) => {
234234
for (const element of value) {
235235
parent.add(element);
236236
}
@@ -260,15 +260,15 @@ export abstract class State {
260260
break;
261261
}
262262
return metaOperations(
263-
(parent, key, value: K) => {
263+
(parent: any, key: any, value: K) => {
264264
if (key != null) {
265265
return Object.assign(parent, {[key]: value});
266266
}
267267
return Object.assign(parent, value);
268268
},
269-
(parent, _, value: K) => {
269+
(parent: any, _: any, value: K) => {
270270
for (const k of Object.keys(value)) {
271-
parent[k] = value[k];
271+
parent[k] = (value as any)[k];
272272
}
273273
return parent;
274274
},
@@ -284,7 +284,7 @@ export abstract class State {
284284
'in the mutation path should be an array, an associative container, or a set');
285285
}
286286

287-
static empty(value): boolean {
287+
static empty(value: any): boolean {
288288
return value == null
289289
|| (value.length === 0
290290
|| (typeof value.length === 'undefined' && Object.keys(value).length === 0));

0 commit comments

Comments
 (0)