From d417f687ab0c81ed72bffbc5dace5f643369bb70 Mon Sep 17 00:00:00 2001 From: Kaur Kuut Date: Sun, 3 Jul 2016 15:09:21 +0300 Subject: [PATCH] Fixed redux dependent definitions. --- react-redux/react-redux-2.1.2-tests.tsx | 14 +++++------ react-redux/react-redux-2.1.2.d.ts | 6 ++--- react-redux/react-redux-tests.tsx | 16 ++++++------- react-redux/react-redux.d.ts | 6 ++--- .../react-router-redux-2.x.d.ts | 4 ++-- react-router-redux/react-router-redux.d.ts | 4 ++-- redux-bootstrap/redux-bootstrap-tests.tsx | 4 ++-- redux-bootstrap/redux-bootstrap.d.ts | 4 ++-- redux-devtools/redux-devtools-2.1.4-tests.tsx | 2 +- redux-devtools/redux-devtools.d.ts | 4 ++-- redux-form/redux-form.d.ts | 14 +++++------ redux-immutable/redux-immutable.d.ts | 2 +- redux-mock-store/redux-mock-store-tests.ts | 2 +- .../redux-promise-middleware-tests.ts | 6 ++--- redux-promise/redux-promise-tests.ts | 7 ++---- redux-promise/redux-promise.d.ts | 19 +++++++++------ redux-saga/redux-saga.d.ts | 2 +- redux-thunk/redux-thunk-tests.ts | 15 ++++++------ redux-thunk/redux-thunk.d.ts | 24 ++++++++++++------- 19 files changed, 81 insertions(+), 74 deletions(-) diff --git a/react-redux/react-redux-2.1.2-tests.tsx b/react-redux/react-redux-2.1.2-tests.tsx index cb791a3d8e..ab32609c01 100644 --- a/react-redux/react-redux-2.1.2-tests.tsx +++ b/react-redux/react-redux-2.1.2-tests.tsx @@ -41,7 +41,7 @@ function mapStateToProps(state: CounterState) { } // Which action creators does it want to receive by props? -function mapDispatchToProps(dispatch: Dispatch) { +function mapDispatchToProps(dispatch: Dispatch) { return { onIncrement: () => dispatch(increment()) }; @@ -78,7 +78,7 @@ ReactDOM.render(( // https://github.com/rackt/react-redux/blob/master/docs/api.md // declare var routes: Route; -declare var store: Store; +declare var store: Store; declare var routerState: RouterState; class MyRootComponent extends Component { @@ -160,7 +160,7 @@ connect(mapStateToProps2, actionCreators)(TodoApp); // return { todos: state.todos }; //} -function mapDispatchToProps2(dispatch: Dispatch) { +function mapDispatchToProps2(dispatch: Dispatch) { return { actions: bindActionCreators(actionCreators, dispatch) }; } @@ -172,7 +172,7 @@ connect(mapStateToProps2, mapDispatchToProps2)(TodoApp); // return { todos: state.todos }; //} -function mapDispatchToProps3(dispatch: Dispatch) { +function mapDispatchToProps3(dispatch: Dispatch) { return bindActionCreators({ addTodo }, dispatch); } @@ -184,7 +184,7 @@ connect(mapStateToProps2, mapDispatchToProps3)(TodoApp); // return { todos: state.todos }; //} -function mapDispatchToProps4(dispatch: Dispatch) { +function mapDispatchToProps4(dispatch: Dispatch) { return { todoActions: bindActionCreators(todoActionCreators, dispatch), counterActions: bindActionCreators(counterActionCreators, dispatch) @@ -199,7 +199,7 @@ connect(mapStateToProps2, mapDispatchToProps4)(TodoApp); // return { todos: state.todos }; //} -function mapDispatchToProps5(dispatch: Dispatch) { +function mapDispatchToProps5(dispatch: Dispatch) { return { actions: bindActionCreators(objectAssign({}, todoActionCreators, counterActionCreators), dispatch) }; @@ -213,7 +213,7 @@ connect(mapStateToProps2, mapDispatchToProps5)(TodoApp); // return { todos: state.todos }; //} -function mapDispatchToProps6(dispatch: Dispatch) { +function mapDispatchToProps6(dispatch: Dispatch) { return bindActionCreators(objectAssign({}, todoActionCreators, counterActionCreators), dispatch); } diff --git a/react-redux/react-redux-2.1.2.d.ts b/react-redux/react-redux-2.1.2.d.ts index fa67b1b2e9..717d831e0e 100644 --- a/react-redux/react-redux-2.1.2.d.ts +++ b/react-redux/react-redux-2.1.2.d.ts @@ -32,11 +32,11 @@ declare module "react-redux" { } interface MapDispatchToPropsFunction { - (dispatch: Dispatch, ownProps?: any): any; + (dispatch: Dispatch, ownProps?: any): any; } interface MapDispatchToPropsObject { - [name: string]: ActionCreator; + [name: string]: ActionCreator; } interface MergeProps { @@ -58,7 +58,7 @@ declare module "react-redux" { /** * The single Redux store in your application. */ - store?: Store; + store?: Store; children?: Function; } diff --git a/react-redux/react-redux-tests.tsx b/react-redux/react-redux-tests.tsx index d22f3aef46..646cdb44a7 100644 --- a/react-redux/react-redux-tests.tsx +++ b/react-redux/react-redux-tests.tsx @@ -41,7 +41,7 @@ function mapStateToProps(state: CounterState) { } // Which action creators does it want to receive by props? -function mapDispatchToProps(dispatch: Dispatch) { +function mapDispatchToProps(dispatch: Dispatch) { return { onIncrement: () => dispatch(increment()) }; @@ -77,7 +77,7 @@ ReactDOM.render(( // API // https://github.com/rackt/react-redux/blob/master/docs/api.md // -declare var store: Store; +declare var store: Store; declare var routerState: RouterState; declare var history: HistoryModule.History; class MyRootComponent extends Component { @@ -165,7 +165,7 @@ connect(mapStateToProps2, actionCreators)(TodoApp); // return { todos: state.todos }; //} -function mapDispatchToProps2(dispatch: Dispatch) { +function mapDispatchToProps2(dispatch: Dispatch) { return { actions: bindActionCreators(actionCreators, dispatch) }; } @@ -177,7 +177,7 @@ connect(mapStateToProps2, mapDispatchToProps2)(TodoApp); // return { todos: state.todos }; //} -function mapDispatchToProps3(dispatch: Dispatch) { +function mapDispatchToProps3(dispatch: Dispatch) { return bindActionCreators({ addTodo }, dispatch); } @@ -189,7 +189,7 @@ connect(mapStateToProps2, mapDispatchToProps3)(TodoApp); // return { todos: state.todos }; //} -function mapDispatchToProps4(dispatch: Dispatch) { +function mapDispatchToProps4(dispatch: Dispatch) { return { todoActions: bindActionCreators(todoActionCreators, dispatch), counterActions: bindActionCreators(counterActionCreators, dispatch) @@ -204,7 +204,7 @@ connect(mapStateToProps2, mapDispatchToProps4)(TodoApp); // return { todos: state.todos }; //} -function mapDispatchToProps5(dispatch: Dispatch) { +function mapDispatchToProps5(dispatch: Dispatch) { return { actions: bindActionCreators(objectAssign({}, todoActionCreators, counterActionCreators), dispatch) }; @@ -218,7 +218,7 @@ connect(mapStateToProps2, mapDispatchToProps5)(TodoApp); // return { todos: state.todos }; //} -function mapDispatchToProps6(dispatch: Dispatch) { +function mapDispatchToProps6(dispatch: Dispatch) { return bindActionCreators(objectAssign({}, todoActionCreators, counterActionCreators), dispatch); } @@ -302,7 +302,7 @@ namespace TestStatelessFunctionWithMapArguments { }; }; - const mapDispatchToProps = (dispatch: Dispatch, ownProps: GreetingProps) => { + const mapDispatchToProps = (dispatch: Dispatch, ownProps: GreetingProps) => { return { onClick: () => { dispatch({ type: 'GREETING', name: ownProps.name }); diff --git a/react-redux/react-redux.d.ts b/react-redux/react-redux.d.ts index 6f05a17b6e..e522264a4a 100644 --- a/react-redux/react-redux.d.ts +++ b/react-redux/react-redux.d.ts @@ -61,11 +61,11 @@ declare module "react-redux" { } interface MapDispatchToPropsFunction { - (dispatch: Dispatch, ownProps?: TOwnProps): TDispatchProps; + (dispatch: Dispatch, ownProps?: TOwnProps): TDispatchProps; } interface MapDispatchToPropsObject { - [name: string]: ActionCreator; + [name: string]: ActionCreator; } interface MergeProps { @@ -92,7 +92,7 @@ declare module "react-redux" { /** * The single Redux store in your application. */ - store?: Store; + store?: Store; children?: ReactNode; } diff --git a/react-router-redux/react-router-redux-2.x.d.ts b/react-router-redux/react-router-redux-2.x.d.ts index a526208612..5e38fe4bee 100644 --- a/react-router-redux/react-router-redux-2.x.d.ts +++ b/react-router-redux/react-router-redux-2.x.d.ts @@ -35,11 +35,11 @@ declare namespace ReactRouterRedux { goBack: GoBackAction; } interface HistoryMiddleware extends R.Middleware { - listenForReplays(store: R.Store, selectLocationState?: Function): void; + listenForReplays(store: R.Store, selectLocationState?: Function): void; unsubscribe(): void; } - function routeReducer(state?: any, options?: any): R.Reducer; + function routeReducer(state?: any, options?: any): R.Reducer; function syncHistory(history: H.History): HistoryMiddleware; } diff --git a/react-router-redux/react-router-redux.d.ts b/react-router-redux/react-router-redux.d.ts index b2c993132a..d91f1ad4e1 100644 --- a/react-router-redux/react-router-redux.d.ts +++ b/react-router-redux/react-router-redux.d.ts @@ -52,8 +52,8 @@ declare namespace ReactRouterRedux { adjustUrlOnReplay?: boolean; } - function routerReducer(state?: any, options?: any): R.Reducer; - function syncHistoryWithStore(history: H.History, store: R.Store, options?: SyncHistoryWithStoreOptions): ReactRouterReduxHistory; + function routerReducer(state?: any, options?: any): R.Reducer; + function syncHistoryWithStore(history: H.History, store: R.Store, options?: SyncHistoryWithStoreOptions): ReactRouterReduxHistory; function routerMiddleware(history: H.History): R.Middleware; } diff --git a/redux-bootstrap/redux-bootstrap-tests.tsx b/redux-bootstrap/redux-bootstrap-tests.tsx index ae6d8063aa..b769063e3e 100644 --- a/redux-bootstrap/redux-bootstrap-tests.tsx +++ b/redux-bootstrap/redux-bootstrap-tests.tsx @@ -9,8 +9,8 @@ let result = bootstrap({ initialState: {}, middlewares: [], reducers: { - reposReducer: (previousState: any, action: any) => { return null; }, - usersReducer: (previousState: any, action: any) => { return null; } + reposReducer: (previousState: any, action: any): any => { return null; }, + usersReducer: (previousState: any, action: any): any => { return null; } }, routes: routes }); diff --git a/redux-bootstrap/redux-bootstrap.d.ts b/redux-bootstrap/redux-bootstrap.d.ts index 933fa988a7..2bfdc53f31 100644 --- a/redux-bootstrap/redux-bootstrap.d.ts +++ b/redux-bootstrap/redux-bootstrap.d.ts @@ -18,13 +18,13 @@ declare module "redux-bootstrap" { } interface BootstrapResult { - store: Redux.Store; + store: Redux.Store; history: ReactRouterRedux.ReactRouterReduxHistory; root: JSX.Element; } interface ReducersOption { - [index: string]: Redux.Reducer; + [index: string]: Redux.Reducer; } export default function bootstrap(options: BootstrapOptions): BootstrapResult; diff --git a/redux-devtools/redux-devtools-2.1.4-tests.tsx b/redux-devtools/redux-devtools-2.1.4-tests.tsx index a57811f16b..6968468315 100644 --- a/redux-devtools/redux-devtools-2.1.4-tests.tsx +++ b/redux-devtools/redux-devtools-2.1.4-tests.tsx @@ -11,7 +11,7 @@ import { Component } from 'react'; declare var m1: Middleware; declare var m2: Middleware; declare var m3: Middleware; -declare var reducer: Reducer; +declare var reducer: Reducer; class CounterApp extends Component { }; class Provider extends Component<{ store: any }, any> { }; diff --git a/redux-devtools/redux-devtools.d.ts b/redux-devtools/redux-devtools.d.ts index 47ad2198d9..e2afe1e160 100644 --- a/redux-devtools/redux-devtools.d.ts +++ b/redux-devtools/redux-devtools.d.ts @@ -10,13 +10,13 @@ declare module "redux-devtools" { interface IDevTools { new (): JSX.ElementClass - instrument(): Function + instrument(): (opts: any) => any; } export function createDevTools(el: React.ReactElement): IDevTools export function persistState(debugSessionKey: string): Function - var factory: { instrument(): Function } + var factory: { instrument(): (opts: any) => any } export default factory; } \ No newline at end of file diff --git a/redux-form/redux-form.d.ts b/redux-form/redux-form.d.ts index dfc2df43a9..edcf9c2c71 100644 --- a/redux-form/redux-form.d.ts +++ b/redux-form/redux-form.d.ts @@ -192,7 +192,7 @@ declare module 'redux-form' { */ handleSubmit?(event:SyntheticEvent):void; - handleSubmit?(submit:(data:FormData, dispatch?:Dispatch) + handleSubmit?(submit:(data:FormData, dispatch?:Dispatch) => Promise|void):FormEventHandler; /** @@ -285,11 +285,11 @@ declare module 'redux-form' { } interface MapDispatchToPropsFunction { - (dispatch:Dispatch, ownProps?:any): any; + (dispatch:Dispatch, ownProps?:any): any; } interface MapDispatchToPropsObject { - [name: string]: ActionCreator; + [name: string]: ActionCreator; } export function reduxForm(config:ReduxFormConfig, @@ -337,7 +337,7 @@ declare module 'redux-form' { * * See Asynchronous Blur Validation Example for more details. */ - asyncValidate?(values:FormData, dispatch:Dispatch, props:Object): + asyncValidate?(values:FormData, dispatch:Dispatch, props:Object): Promise; /** @@ -377,7 +377,7 @@ declare module 'redux-form' { * you must pass it as a parameter to handleSubmit() inside your form * component. */ - onSubmit?(values:FormData, dispatch?:Dispatch): any; + onSubmit?(values:FormData, dispatch?:Dispatch): any; /** * If true, the form values will be overwritten whenever the initialValues @@ -466,7 +466,7 @@ declare module 'redux-form' { [formName:string]: { [fieldName:string]: Normalizer } - }):Reducer; + }):Reducer; /** * Returns a form reducer that will also pass each action through @@ -475,6 +475,6 @@ declare module 'redux-form' { * passed to each reducer will only be the slice that pertains to that * form. */ - plugin(reducers:{[formName:string]: Reducer}):Reducer; + plugin(reducers:{[formName:string]: Reducer}):Reducer; } } diff --git a/redux-immutable/redux-immutable.d.ts b/redux-immutable/redux-immutable.d.ts index df0f3745af..8d235b9338 100644 --- a/redux-immutable/redux-immutable.d.ts +++ b/redux-immutable/redux-immutable.d.ts @@ -6,5 +6,5 @@ /// declare module "redux-immutable" { - export function combineReducers(reducers : Object): Redux.Reducer; + export function combineReducers(reducers: Object): Redux.Reducer; } diff --git a/redux-mock-store/redux-mock-store-tests.ts b/redux-mock-store/redux-mock-store-tests.ts index 1b0a53968b..4a6045c288 100644 --- a/redux-mock-store/redux-mock-store-tests.ts +++ b/redux-mock-store/redux-mock-store-tests.ts @@ -19,7 +19,7 @@ function counter(state: any, action: any) { } function loggingMiddleware() { - return (next: Redux.Dispatch) => (action: any) => { + return (next: Redux.Dispatch) => (action: any) => { console.log(action.type); next(action); }; diff --git a/redux-promise-middleware/redux-promise-middleware-tests.ts b/redux-promise-middleware/redux-promise-middleware-tests.ts index ef7e7d82de..64fde63170 100644 --- a/redux-promise-middleware/redux-promise-middleware-tests.ts +++ b/redux-promise-middleware/redux-promise-middleware-tests.ts @@ -4,7 +4,7 @@ import { createStore, applyMiddleware, Store, Dispatch } from "redux"; import promiseMiddleware from "redux-promise-middleware"; -declare var rootReducer: Function; +declare var rootReducer: (state: any, action: any) => any; declare var Promise: any; declare var doSomethingAsyncAndReturnPromise: any; declare var someActionCreator: any; @@ -13,7 +13,7 @@ const createStoreWithMiddleware = applyMiddleware( promiseMiddleware() )(createStore); -const store: Store = createStoreWithMiddleware(rootReducer); +const store: Store = createStoreWithMiddleware(rootReducer); export function myAsyncActionCreator(data: any) { return { @@ -38,7 +38,7 @@ const actionCreator1 = () => ({ const actionCreator2 = () => ({ type: "FIRST_ACTION_TYPE", payload: { - promise: Promise.resolve((action: string, dispatch: Redux.Dispatch, getState: Function) => { + promise: Promise.resolve((action: string, dispatch: Redux.Dispatch, getState: Function) => { dispatch({ type: "SECEOND_ACTION_TYPE", payload: "..." }); dispatch(someActionCreator()); }) diff --git a/redux-promise/redux-promise-tests.ts b/redux-promise/redux-promise-tests.ts index 8859eaac52..724f695261 100644 --- a/redux-promise/redux-promise-tests.ts +++ b/redux-promise/redux-promise-tests.ts @@ -3,9 +3,8 @@ /// import {createAction} from 'redux-actions'; -import { createStore, applyMiddleware } from 'redux'; +import { createStore, applyMiddleware, PromiseAction } from 'redux'; import promise from 'redux-promise'; -import PromiseInterface = ReduxPromise.PromiseInterface; declare var userReducer: any; @@ -18,11 +17,9 @@ appStore.dispatch( listUsers() ); -function listUsers(): PromiseInterface { +function listUsers(): PromiseAction { return createAction('LIST_USERS', () => { return Promise.resolve([{ email: 'me@definitely.typed' }]); }); } - - diff --git a/redux-promise/redux-promise.d.ts b/redux-promise/redux-promise.d.ts index 58b6d712a6..f3fbea7240 100644 --- a/redux-promise/redux-promise.d.ts +++ b/redux-promise/redux-promise.d.ts @@ -1,18 +1,23 @@ // Type definitions for redux-promise v0.5.3 // Project: https://github.com/acdlite/redux-promise -// Definitions by: Rogelio Morrell Caballero +// Definitions by: Rogelio Morrell Caballero , Kaur Kuut // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped /// +declare namespace Redux { + type PromiseAction = (dispatch: Redux.Dispatch, getState?: () => S) => any; + + interface Dispatch { + (asyncAction: PromiseAction): R; + } +} + declare namespace ReduxPromise { - export interface Promise extends Redux.Middleware {} - export interface PromiseInterface { - (dispatch: Redux.Dispatch, getState?: () => T): any; - } + export interface Promise extends Redux.Middleware {} } declare module "redux-promise" { - var promise: ReduxPromise.Promise; - export default promise; + var promise: ReduxPromise.Promise; + export default promise; } \ No newline at end of file diff --git a/redux-saga/redux-saga.d.ts b/redux-saga/redux-saga.d.ts index 8df9f63a9c..638099f6c6 100644 --- a/redux-saga/redux-saga.d.ts +++ b/redux-saga/redux-saga.d.ts @@ -118,7 +118,7 @@ declare module 'redux-saga/lib/runSaga' { subscribe: (cb: Function) => Function; } - export function storeIO(store: Store): IO; + export function storeIO(store: Store): IO; export function runSaga(iterator: Iterable, io: IO, diff --git a/redux-thunk/redux-thunk-tests.ts b/redux-thunk/redux-thunk-tests.ts index f1283bf53c..a900c799ed 100644 --- a/redux-thunk/redux-thunk-tests.ts +++ b/redux-thunk/redux-thunk-tests.ts @@ -2,11 +2,10 @@ /// /// -import { createStore, applyMiddleware, Store, Dispatch } from 'redux'; +import { createStore, applyMiddleware, Store, Dispatch, ThunkAction } from 'redux'; import thunk from 'redux-thunk'; -import ThunkInterface = ReduxThunk.ThunkInterface; -declare var rootReducer: Function; +declare var rootReducer: (state: any, action: any) => any; declare var fetch: any; // create a store that has redux-thunk middleware enabled @@ -14,7 +13,7 @@ const createStoreWithMiddleware = applyMiddleware( thunk )(createStore); -const store: Store = createStoreWithMiddleware(rootReducer); +const store: Store = createStoreWithMiddleware(rootReducer); function fetchSecretSauce() { return fetch('https://www.google.com/search?q=secret+sauce'); @@ -58,13 +57,13 @@ store.dispatch(withdrawMoney(100)); // A thunk is a function that returns a function. // This is a thunk. -function makeASandwichWithSecretSauce(forPerson: any): ThunkInterface { +function makeASandwichWithSecretSauce(forPerson: any): ThunkAction { // Invert control! // Return a function that accepts `dispatch` so we can dispatch later. // Thunk middleware knows how to turn thunk async actions into actions. - return function (dispatch: Dispatch): any { + return function (dispatch: Dispatch): any { return fetchSecretSauce().then( (sauce: any) => dispatch(makeASandwich(forPerson, sauce)), (error: any) => dispatch(apologize('The Sandwich Shop', forPerson, error)) @@ -92,8 +91,8 @@ store.dispatch( // actions and async actions from other action creators, // and I can build my control flow with Promises. -function makeSandwichesForEverybody(): ThunkInterface { - return function (dispatch: Dispatch, getState: () => any): any { +function makeSandwichesForEverybody(): ThunkAction { + return function (dispatch: Dispatch, getState: () => any): any { if (!getState().sandwiches.isShopOpen) { // You don’t have to return Promises, but it’s a handy convention diff --git a/redux-thunk/redux-thunk.d.ts b/redux-thunk/redux-thunk.d.ts index d19d2a2d0c..08f62bc99e 100644 --- a/redux-thunk/redux-thunk.d.ts +++ b/redux-thunk/redux-thunk.d.ts @@ -1,18 +1,24 @@ -// Type definitions for redux-thunk v2.0.1 +// Type definitions for redux-thunk v2.1.0 // Project: https://github.com/gaearon/redux-thunk -// Definitions by: Qubo +// Definitions by: Qubo , Kaur Kuut // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped /// -declare namespace ReduxThunk { - export interface Thunk extends Redux.Middleware {} - export interface ThunkInterface { - (dispatch: Redux.Dispatch, getState?: () => T): any; - } +declare namespace Redux { + type ThunkAction = (dispatch: Dispatch, getState: () => S, extraArgument: E) => R; + + interface Dispatch { + (asyncAction: ThunkAction): R; + } } declare module "redux-thunk" { - var thunk: ReduxThunk.Thunk; - export default thunk; + import { Middleware } from "redux"; + + const thunk: Middleware & { + withExtraArgument(extraArgument: any): Middleware; + }; + + export default thunk; }