Skip to content

Commit b0ec79c

Browse files
committed
Add TypeScript definitions
1 parent 9095294 commit b0ec79c

File tree

4 files changed

+58
-1
lines changed

4 files changed

+58
-1
lines changed

index.d.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import {Middleware} from "redux";
2+
3+
4+
declare module "redux" {
5+
export interface Dispatch<S> {
6+
<R>(asyncAction: (dispatch: Dispatch<S>,
7+
getState?: () => S,
8+
extraArgument?: any) => R): R;
9+
}
10+
}
11+
12+
13+
declare const thunk: Middleware & {
14+
withExtraArgument(extraArgument: any): Middleware;
15+
};
16+
17+
export default thunk;

package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@
44
"description": "Thunk middleware for Redux.",
55
"main": "lib/index.js",
66
"jsnext:main": "es/index.js",
7+
"typings": "./index.d.ts",
78
"files": [
89
"lib",
910
"es",
1011
"src",
11-
"dist"
12+
"dist",
13+
"index.d.ts"
1214
],
1315
"scripts": {
1416
"clean": "rimraf lib dist es",
@@ -67,7 +69,10 @@
6769
"eslint-config-airbnb": "1.0.2",
6870
"eslint-plugin-react": "^4.1.0",
6971
"mocha": "^2.2.5",
72+
"redux": "^3.4.0",
7073
"rimraf": "^2.5.2",
74+
"typescript": "^1.8.10",
75+
"typescript-definition-tester": "0.0.4",
7176
"webpack": "^1.12.14"
7277
}
7378
}

test/index.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import chai from 'chai';
22
import thunkMiddleware from '../src/index';
3+
import * as tt from 'typescript-definition-tester';
4+
35

46
describe('thunk middleware', () => {
57
const doDispatch = () => {};
@@ -91,4 +93,16 @@ describe('thunk middleware', () => {
9193
});
9294
});
9395
});
96+
97+
describe('TypeScript definitions', function test() {
98+
this.timeout(0);
99+
100+
it('should compile against index.d.ts', (done) => {
101+
tt.compileDirectory(
102+
__dirname,
103+
fileName => fileName.match(/\.ts$/),
104+
() => done()
105+
);
106+
});
107+
});
94108
});

test/typescript.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import {Store, Middleware} from 'redux';
2+
import thunk from '../index.d.ts';
3+
4+
5+
declare const store: Store<{foo: string}>;
6+
7+
store.dispatch(dispatch => {
8+
dispatch({type: 'FOO'});
9+
});
10+
11+
store.dispatch((dispatch, getState) => {
12+
const state = getState();
13+
14+
const foo: string = state.foo;
15+
});
16+
17+
const middleware: Middleware = thunk.withExtraArgument('bar');
18+
19+
store.dispatch((dispatch, getState, extraArg) => {
20+
console.log(extraArg);
21+
});

0 commit comments

Comments
 (0)