File tree Expand file tree Collapse file tree 4 files changed +58
-1
lines changed Expand file tree Collapse file tree 4 files changed +58
-1
lines changed Original file line number Diff line number Diff line change
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 ;
Original file line number Diff line number Diff line change 4
4
"description" : " Thunk middleware for Redux." ,
5
5
"main" : " lib/index.js" ,
6
6
"jsnext:main" : " es/index.js" ,
7
+ "typings" : " ./index.d.ts" ,
7
8
"files" : [
8
9
" lib" ,
9
10
" es" ,
10
11
" src" ,
11
- " dist"
12
+ " dist" ,
13
+ " index.d.ts"
12
14
],
13
15
"scripts" : {
14
16
"clean" : " rimraf lib dist es" ,
67
69
"eslint-config-airbnb" : " 1.0.2" ,
68
70
"eslint-plugin-react" : " ^4.1.0" ,
69
71
"mocha" : " ^2.2.5" ,
72
+ "redux" : " ^3.4.0" ,
70
73
"rimraf" : " ^2.5.2" ,
74
+ "typescript" : " ^1.8.10" ,
75
+ "typescript-definition-tester" : " 0.0.4" ,
71
76
"webpack" : " ^1.12.14"
72
77
}
73
78
}
Original file line number Diff line number Diff line change 1
1
import chai from 'chai' ;
2
2
import thunkMiddleware from '../src/index' ;
3
+ import * as tt from 'typescript-definition-tester' ;
4
+
3
5
4
6
describe ( 'thunk middleware' , ( ) => {
5
7
const doDispatch = ( ) => { } ;
@@ -91,4 +93,16 @@ describe('thunk middleware', () => {
91
93
} ) ;
92
94
} ) ;
93
95
} ) ;
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 ( / \. t s $ / ) ,
104
+ ( ) => done ( )
105
+ ) ;
106
+ } ) ;
107
+ } ) ;
94
108
} ) ;
Original file line number Diff line number Diff line change
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
+ } ) ;
You can’t perform that action at this time.
0 commit comments