Skip to content

Commit bb6feaa

Browse files
committed
Update to typescript 2.4
Adapt to 2.4's stricter checks. Also add `skipLibChecks === true` to `tsconfig.json` because Angular has it's own ts-2.4-related issues. Will remove the flag once it's fixed.
1 parent 4454776 commit bb6feaa

14 files changed

+358
-3406
lines changed

package-lock.json

-3,090
This file was deleted.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
"tsconfig-paths": "^2.2.0",
7878
"tslint": "^5.1.0",
7979
"typedoc": "^0.6.0",
80-
"typescript": "^2.3.4",
80+
"typescript": "^2.4.1",
8181
"zone.js": "^0.8.4"
8282
},
8383
"peerDependencies": {

src/components/fractal-reducer-map.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ export function replaceLocalReducer(
4040

4141
function rootFractalReducer(
4242
state: {} = {},
43-
action: Action & { '@angular-redux::fractalkey': string }) {
43+
action: Action & { '@angular-redux::fractalkey'?: string }) {
4444
const fractalKey = action['@angular-redux::fractalkey'];
4545
const fractalPath = fractalKey ? JSON.parse(fractalKey) : [];
46-
const localReducer = reducerMap[fractalKey];
46+
const localReducer = reducerMap[fractalKey || ''];
4747
return fractalKey && localReducer ?
4848
setIn(
4949
state,

src/components/root-store.spec.ts

+1-7
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,7 @@ class MockNgZone {
1515
run = (fn: Function) => fn()
1616
}
1717

18-
interface IAppState {
19-
foo: string;
20-
bar: string;
21-
baz: number;
22-
}
23-
24-
type PayloadAction = Action & { payload: string | number };
18+
type PayloadAction = Action & { payload?: string | number };
2519

2620
describe('NgRedux Observable Store', () => {
2721
interface IAppState {

src/components/sub-store.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export class SubStore<State> implements ObservableStore<State> {
2626
registerFractalReducer(basePath, localReducer);
2727
}
2828

29-
dispatch: Dispatch<State> = (action: Action) =>
29+
dispatch: Dispatch<State> = action =>
3030
this.rootStore.dispatch(
3131
Object.assign({},
3232
action,

src/decorators/dispatch.spec.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ interface IAppState {
1414
instanceProperty?: string;
1515
}
1616

17-
type PayloadAction = Action & { payload: IAppState };
17+
type PayloadAction = Action & { payload?: IAppState };
1818

1919
describe('@dispatch', () => {
2020
let ngRedux;
@@ -31,7 +31,7 @@ describe('@dispatch', () => {
3131
rootReducer = (state = defaultState, action: PayloadAction) => {
3232
switch (action.type) {
3333
case 'TEST':
34-
const { value, instanceProperty } = action.payload;
34+
const { value = null, instanceProperty = null } = action.payload || {};
3535
return Object.assign({}, state, { value, instanceProperty });
3636
default:
3737
return state;
@@ -78,8 +78,8 @@ describe('@dispatch', () => {
7878
}
7979
};
8080
expect(result.type).toBe('TEST');
81-
expect(result.payload.value).toBe('class method');
82-
expect(result.payload.instanceProperty).toBe('test');
81+
expect(result.payload && result.payload.value).toBe('class method');
82+
expect(result.payload && result.payload.instanceProperty).toBe('test');
8383
expect(NgRedux.instance).toBeTruthy();
8484
expect(NgRedux.instance && NgRedux.instance.dispatch)
8585
.toHaveBeenCalledWith(expectedArgs)
@@ -95,8 +95,8 @@ describe('@dispatch', () => {
9595
}
9696
}
9797
expect(result.type).toBe('TEST');
98-
expect(result.payload.value).toBe('bound property');
99-
expect(result.payload.instanceProperty).toBe('test');
98+
expect(result.payload && result.payload.value).toBe('bound property');
99+
expect(result.payload && result.payload.instanceProperty).toBe('test');
100100
expect(NgRedux.instance).toBeTruthy();
101101
expect(NgRedux.instance && NgRedux.instance.dispatch)
102102
.toHaveBeenCalledWith(expectedArgs)
@@ -123,8 +123,8 @@ describe('@dispatch', () => {
123123
}
124124
}
125125
expect(result.type).toBe('TEST');
126-
expect(result.payload.value).toBe('external function');
127-
expect(result.payload.instanceProperty).toBe('test');
126+
expect(result.payload && result.payload.value).toBe('external function');
127+
expect(result.payload && result.payload.instanceProperty).toBe('test');
128128
expect(NgRedux.instance).toBeTruthy();
129129
expect(NgRedux.instance && NgRedux.instance.dispatch)
130130
.toHaveBeenCalledWith(expectedArgs)

src/decorators/select.spec.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ interface IAppState {
1414
baz: number;
1515
}
1616

17-
type PayloadAction = Action & { payload: any };
17+
type PayloadAction = Action & { payload?: any };
1818

1919
class MockNgZone { run = (fn: Function) => fn() }
2020

@@ -116,9 +116,9 @@ describe('Select decorators', () => {
116116

117117
it('should receive previous and next value for comparison', done => {
118118
const spy = jasmine.createSpy('spy');
119-
class MockClass { @select('baz', spy) baz$: Observable<number>; }
119+
class LocalMockClass { @select('baz', spy) baz$: Observable<number>; }
120120

121-
const mockInstance = new MockClass();
121+
const mockInstance = new LocalMockClass();
122122
mockInstance
123123
.baz$
124124
.take(3)

src/decorators/with-sub-store.spec.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Action } from 'redux';
33

44
import { Observable } from 'rxjs/Observable';
55
import 'rxjs/add/operator/take';
6+
import 'rxjs/add/operator/toArray';
67

78
import { WithSubStore } from './with-sub-store';
89
import { select, select$ } from './select';
@@ -131,7 +132,7 @@ describe('@WithSubStore', () => {
131132

132133
it('handle a base path with no extant store data', () => {
133134
const iDontExistYetReducer =
134-
(state: any, action: Action & { newValue: string }) =>
135+
(state: any, action: Action & { newValue?: string }) =>
135136
({ ...state, nonexistentkey: action.newValue });
136137

137138
@WithSubStore({ basePathMethodName, localReducer: iDontExistYetReducer })

testing/observable-store.mock.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
} from '@angular-redux/store';
88
import { Observable } from 'rxjs/Observable';
99
import { Subject } from 'rxjs/Subject';
10-
import { Reducer, Action } from 'redux';
10+
import { Reducer, Action, Dispatch } from 'redux';
1111
import { ReplaySubject } from 'rxjs/ReplaySubject';
1212
import 'rxjs/add/observable/from';
1313
import 'rxjs/add/operator/distinctUntilChanged';
@@ -44,9 +44,9 @@ export class MockObservableStore<State> implements ObservableStore<any> {
4444
this.subStores = {};
4545
}
4646

47-
dispatch = (action: Action) => action;
47+
dispatch: Dispatch<State> = action => action;
4848
replaceReducer = () => null;
49-
getState = () => null;
49+
getState = () => ({} as State);
5050
subscribe = () => () => null;
5151

5252
select = <SelectedState>(
@@ -63,11 +63,11 @@ export class MockObservableStore<State> implements ObservableStore<any> {
6363
localReducer: Reducer<SubState>): MockObservableStore<SubState> =>
6464
this.initSubStore<SubState>(basePath)
6565

66-
getSubStore = (...pathSelectors: PathSelector[]): MockObservableStore<any> => {
66+
getSubStore = <SubState>(...pathSelectors: PathSelector[]): MockObservableStore<any> => {
6767
const [ first, ...rest ] = pathSelectors;
68-
return first ?
68+
return (first ?
6969
this.initSubStore(first).getSubStore(...rest) :
70-
this;
70+
this) as MockObservableStore<SubState>;
7171
}
7272

7373
private initSubStore<SubState>(basePath: PathSelector) {

tsconfig.build.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
"strict": true,
1919
"paths": {
2020
"@angular-redux/store": [ "./src/index.ts" ]
21-
}
21+
},
22+
"skipLibCheck": true
2223
},
2324
"compileOnSave": false,
2425
"buildOnSave": false,

tsconfig.docs.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
"paths": {
1515
"@angular-redux/store": ["src/index.ts"]
1616
},
17-
"strict": true
17+
"strict": true,
18+
"skipLibCheck": true
1819
},
1920
"compileOnSave": false,
2021
"buildOnSave": false,

tsconfig.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
"paths": {
1919
"@angular-redux/store": ["src/index.ts"]
2020
},
21-
"strict": true
21+
"strict": true,
22+
"skipLibCheck": true
2223
},
2324
"compileOnSave": false,
2425
"buildOnSave": false,

tsconfig.testing.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
"paths": {
1515
"@angular-redux/store": ["./lib/src"]
1616
},
17-
"strict": true
17+
"strict": true,
18+
"skipLibCheck": true
1819
},
1920
"compileOnSave": false,
2021
"buildOnSave": false,

0 commit comments

Comments
 (0)