Skip to content

Commit 196df61

Browse files
author
Wang Zhongliang
committed
WIP: Refine test cases
1 parent 4eb7404 commit 196df61

File tree

7 files changed

+2836
-19
lines changed

7 files changed

+2836
-19
lines changed

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"typescript.tsdk": "node_modules/typescript/lib"
3+
}

index.d.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,17 @@
11
import { Middleware, Action, AnyAction } from "redux";
22

3+
interface ThunkDispatch<S, E, A extends Action> {
4+
<T extends A>(action: T): T;
5+
<R>(asyncAction: ThunkAction<R, S, E, A>): R;
6+
}
37

48
export type ThunkAction<R, S, E, A extends Action> = (
59
dispatch: ThunkDispatch<S, E, A>,
610
getState: () => S,
711
extraArgument: E
812
) => R;
913

10-
interface ThunkDispatch<S, E, A extends Action> {
11-
<T extends A>(action: T): T;
12-
}
13-
14-
interface ThunkDispatch<S, E, A extends Action> {
15-
<R>(asyncAction: ThunkAction<R, S, E, A>): R;
16-
}
17-
18-
type ThunkMiddleware<E, S = {}, A extends Action = AnyAction> = Middleware<ThunkDispatch<S, E, A>, S, ThunkDispatch<S, E, A>>;
14+
type ThunkMiddleware<E> = Middleware<ThunkDispatch<S, E, A>, S, ThunkDispatch<S, E, A>>;
1915

2016
declare const thunk: ThunkMiddleware<undefined> & {
2117
withExtraArgument<E>(extraArgument: E): ThunkMiddleware<E>

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@
7171
"mocha": "^2.2.5",
7272
"redux": "4.0.0-beta.2",
7373
"rimraf": "^2.5.2",
74-
"typescript": "~2.4.0",
75-
"typescript-definition-tester": "0.0.5",
74+
"typescript": "~2.6.0",
75+
"typings-tester": "^0.3.1",
7676
"webpack": "^1.12.14"
7777
}
7878
}

test/index.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import chai from 'chai';
22
import thunkMiddleware from '../src/index';
3-
import * as tt from 'typescript-definition-tester';
3+
import { check } from 'typings-tester';
44

55

66
describe('thunk middleware', () => {
@@ -97,12 +97,8 @@ describe('thunk middleware', () => {
9797
describe('TypeScript definitions', function test() {
9898
this.timeout(0);
9999

100-
it('should compile against index.d.ts', (done) => {
101-
tt.compileDirectory(
102-
__dirname,
103-
fileName => fileName.match(/\.ts$/),
104-
() => done()
105-
);
100+
it('should compile against index.d.ts', () => {
101+
check([__dirname + '/typescript.ts'], __dirname + '/tsconfig.json');
106102
});
107103
});
108104
});

test/tsconfig.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"compilerOptions": {
3+
"strict": true
4+
},
5+
"files": [
6+
"./*.ts"
7+
]
8+
}

test/typescript.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@ type State = {
77

88
type Actions = { type: 'FOO' };
99

10-
function fakeReducer(state: State, action: Actions): State {
10+
const initialState: State = {
11+
foo: 'foo'
12+
};
13+
14+
function fakeReducer(state: State = initialState, action: Actions): State {
1115
return state;
1216
}
1317

0 commit comments

Comments
 (0)