Skip to content

Commit

Permalink
Update to typescript 2.4
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
SethDavenport committed Jul 9, 2017
1 parent 4454776 commit d0fdaba
Show file tree
Hide file tree
Showing 14 changed files with 358 additions and 3,406 deletions.
3,090 changes: 0 additions & 3,090 deletions package-lock.json

This file was deleted.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
"tsconfig-paths": "^2.2.0",
"tslint": "^5.1.0",
"typedoc": "^0.6.0",
"typescript": "^2.3.4",
"typescript": "^2.4.1",
"zone.js": "^0.8.4"
},
"peerDependencies": {
Expand Down
4 changes: 2 additions & 2 deletions src/components/fractal-reducer-map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ export function replaceLocalReducer(

function rootFractalReducer(
state: {} = {},
action: Action & { '@angular-redux::fractalkey': string }) {
action: Action & { '@angular-redux::fractalkey'?: string }) {
const fractalKey = action['@angular-redux::fractalkey'];
const fractalPath = fractalKey ? JSON.parse(fractalKey) : [];
const localReducer = reducerMap[fractalKey];
const localReducer = reducerMap[fractalKey || ''];
return fractalKey && localReducer ?
setIn(
state,
Expand Down
8 changes: 1 addition & 7 deletions src/components/root-store.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,7 @@ class MockNgZone {
run = (fn: Function) => fn()
}

interface IAppState {
foo: string;
bar: string;
baz: number;
}

type PayloadAction = Action & { payload: string | number };
type PayloadAction = Action & { payload?: string | number };

describe('NgRedux Observable Store', () => {
interface IAppState {
Expand Down
2 changes: 1 addition & 1 deletion src/components/sub-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class SubStore<State> implements ObservableStore<State> {
registerFractalReducer(basePath, localReducer);
}

dispatch: Dispatch<State> = (action: Action) =>
dispatch: Dispatch<State> = <A extends Action>(action: A) =>
this.rootStore.dispatch(
Object.assign({},
action,
Expand Down
16 changes: 8 additions & 8 deletions src/decorators/dispatch.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ interface IAppState {
instanceProperty?: string;
}

type PayloadAction = Action & { payload: IAppState };
type PayloadAction = Action & { payload?: IAppState };

describe('@dispatch', () => {
let ngRedux;
Expand All @@ -31,7 +31,7 @@ describe('@dispatch', () => {
rootReducer = (state = defaultState, action: PayloadAction) => {
switch (action.type) {
case 'TEST':
const { value, instanceProperty } = action.payload;
const { value = null, instanceProperty = null } = action.payload || {};
return Object.assign({}, state, { value, instanceProperty });
default:
return state;
Expand Down Expand Up @@ -78,8 +78,8 @@ describe('@dispatch', () => {
}
};
expect(result.type).toBe('TEST');
expect(result.payload.value).toBe('class method');
expect(result.payload.instanceProperty).toBe('test');
expect(result.payload && result.payload.value).toBe('class method');
expect(result.payload && result.payload.instanceProperty).toBe('test');
expect(NgRedux.instance).toBeTruthy();
expect(NgRedux.instance && NgRedux.instance.dispatch)
.toHaveBeenCalledWith(expectedArgs)
Expand All @@ -95,8 +95,8 @@ describe('@dispatch', () => {
}
}
expect(result.type).toBe('TEST');
expect(result.payload.value).toBe('bound property');
expect(result.payload.instanceProperty).toBe('test');
expect(result.payload && result.payload.value).toBe('bound property');
expect(result.payload && result.payload.instanceProperty).toBe('test');
expect(NgRedux.instance).toBeTruthy();
expect(NgRedux.instance && NgRedux.instance.dispatch)
.toHaveBeenCalledWith(expectedArgs)
Expand All @@ -123,8 +123,8 @@ describe('@dispatch', () => {
}
}
expect(result.type).toBe('TEST');
expect(result.payload.value).toBe('external function');
expect(result.payload.instanceProperty).toBe('test');
expect(result.payload && result.payload.value).toBe('external function');
expect(result.payload && result.payload.instanceProperty).toBe('test');
expect(NgRedux.instance).toBeTruthy();
expect(NgRedux.instance && NgRedux.instance.dispatch)
.toHaveBeenCalledWith(expectedArgs)
Expand Down
6 changes: 3 additions & 3 deletions src/decorators/select.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ interface IAppState {
baz: number;
}

type PayloadAction = Action & { payload: any };
type PayloadAction = Action & { payload?: any };

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

Expand Down Expand Up @@ -116,9 +116,9 @@ describe('Select decorators', () => {

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

const mockInstance = new MockClass();
const mockInstance = new LocalMockClass();
mockInstance
.baz$
.take(3)
Expand Down
3 changes: 2 additions & 1 deletion src/decorators/with-sub-store.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Action } from 'redux';

import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/take';
import 'rxjs/add/operator/toArray';

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

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

@WithSubStore({ basePathMethodName, localReducer: iDontExistYetReducer })
Expand Down
12 changes: 6 additions & 6 deletions testing/observable-store.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
} from '@angular-redux/store';
import { Observable } from 'rxjs/Observable';
import { Subject } from 'rxjs/Subject';
import { Reducer, Action } from 'redux';
import { Reducer, Action, Dispatch } from 'redux';
import { ReplaySubject } from 'rxjs/ReplaySubject';
import 'rxjs/add/observable/from';
import 'rxjs/add/operator/distinctUntilChanged';
Expand Down Expand Up @@ -44,9 +44,9 @@ export class MockObservableStore<State> implements ObservableStore<any> {
this.subStores = {};
}

dispatch = (action: Action) => action;
dispatch: Dispatch<State> = action => action;
replaceReducer = () => null;
getState = () => null;
getState = () => ({} as State);
subscribe = () => () => null;

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

getSubStore = (...pathSelectors: PathSelector[]): MockObservableStore<any> => {
getSubStore = <SubState>(...pathSelectors: PathSelector[]): MockObservableStore<any> => {
const [ first, ...rest ] = pathSelectors;
return first ?
return (first ?
this.initSubStore(first).getSubStore(...rest) :
this;
this) as MockObservableStore<SubState>;
}

private initSubStore<SubState>(basePath: PathSelector) {
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"strict": true,
"paths": {
"@angular-redux/store": [ "./src/index.ts" ]
}
},
"skipLibCheck": true
},
"compileOnSave": false,
"buildOnSave": false,
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"paths": {
"@angular-redux/store": ["src/index.ts"]
},
"strict": true
"strict": true,
"skipLibCheck": true
},
"compileOnSave": false,
"buildOnSave": false,
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"paths": {
"@angular-redux/store": ["src/index.ts"]
},
"strict": true
"strict": true,
"skipLibCheck": true
},
"compileOnSave": false,
"buildOnSave": false,
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.testing.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"paths": {
"@angular-redux/store": ["./lib/src"]
},
"strict": true
"strict": true,
"skipLibCheck": true
},
"compileOnSave": false,
"buildOnSave": false,
Expand Down
Loading

0 comments on commit d0fdaba

Please sign in to comment.