Fixed redux dependent definitions.

This commit is contained in:
Kaur Kuut
2016-07-03 15:09:21 +03:00
parent 15ddcf3127
commit d417f687ab
19 changed files with 81 additions and 74 deletions
+7 -7
View File
@@ -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<CounterState>) {
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<TodoState>;
declare var routerState: RouterState;
class MyRootComponent extends Component<any, any> {
@@ -160,7 +160,7 @@ connect(mapStateToProps2, actionCreators)(TodoApp);
// return { todos: state.todos };
//}
function mapDispatchToProps2(dispatch: Dispatch) {
function mapDispatchToProps2(dispatch: Dispatch<TodoState>) {
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<TodoState>) {
return bindActionCreators({ addTodo }, dispatch);
}
@@ -184,7 +184,7 @@ connect(mapStateToProps2, mapDispatchToProps3)(TodoApp);
// return { todos: state.todos };
//}
function mapDispatchToProps4(dispatch: Dispatch) {
function mapDispatchToProps4(dispatch: Dispatch<TodoState>) {
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<TodoState>) {
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<TodoState>) {
return bindActionCreators(objectAssign({}, todoActionCreators, counterActionCreators), dispatch);
}
+3 -3
View File
@@ -32,11 +32,11 @@ declare module "react-redux" {
}
interface MapDispatchToPropsFunction {
(dispatch: Dispatch, ownProps?: any): any;
(dispatch: Dispatch<any>, ownProps?: any): any;
}
interface MapDispatchToPropsObject {
[name: string]: ActionCreator;
[name: string]: ActionCreator<any>;
}
interface MergeProps {
@@ -58,7 +58,7 @@ declare module "react-redux" {
/**
* The single Redux store in your application.
*/
store?: Store;
store?: Store<any>;
children?: Function;
}
+8 -8
View File
@@ -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<CounterState>) {
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<TodoState>;
declare var routerState: RouterState;
declare var history: HistoryModule.History;
class MyRootComponent extends Component<any, any> {
@@ -165,7 +165,7 @@ connect(mapStateToProps2, actionCreators)(TodoApp);
// return { todos: state.todos };
//}
function mapDispatchToProps2(dispatch: Dispatch) {
function mapDispatchToProps2(dispatch: Dispatch<TodoState>) {
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<TodoState>) {
return bindActionCreators({ addTodo }, dispatch);
}
@@ -189,7 +189,7 @@ connect(mapStateToProps2, mapDispatchToProps3)(TodoApp);
// return { todos: state.todos };
//}
function mapDispatchToProps4(dispatch: Dispatch) {
function mapDispatchToProps4(dispatch: Dispatch<TodoState>) {
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<TodoState>) {
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<TodoState>) {
return bindActionCreators(objectAssign({}, todoActionCreators, counterActionCreators), dispatch);
}
@@ -302,7 +302,7 @@ namespace TestStatelessFunctionWithMapArguments {
};
};
const mapDispatchToProps = (dispatch: Dispatch, ownProps: GreetingProps) => {
const mapDispatchToProps = (dispatch: Dispatch<any>, ownProps: GreetingProps) => {
return {
onClick: () => {
dispatch({ type: 'GREETING', name: ownProps.name });
+3 -3
View File
@@ -61,11 +61,11 @@ declare module "react-redux" {
}
interface MapDispatchToPropsFunction<TDispatchProps, TOwnProps> {
(dispatch: Dispatch, ownProps?: TOwnProps): TDispatchProps;
(dispatch: Dispatch<any>, ownProps?: TOwnProps): TDispatchProps;
}
interface MapDispatchToPropsObject {
[name: string]: ActionCreator;
[name: string]: ActionCreator<any>;
}
interface MergeProps<TStateProps, TDispatchProps, TOwnProps> {
@@ -92,7 +92,7 @@ declare module "react-redux" {
/**
* The single Redux store in your application.
*/
store?: Store;
store?: Store<any>;
children?: ReactNode;
}
+2 -2
View File
@@ -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<any>, selectLocationState?: Function): void;
unsubscribe(): void;
}
function routeReducer(state?: any, options?: any): R.Reducer;
function routeReducer(state?: any, options?: any): R.Reducer<any>;
function syncHistory(history: H.History): HistoryMiddleware;
}
+2 -2
View File
@@ -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<any>;
function syncHistoryWithStore(history: H.History, store: R.Store<any>, options?: SyncHistoryWithStoreOptions): ReactRouterReduxHistory;
function routerMiddleware(history: H.History): R.Middleware;
}
+2 -2
View File
@@ -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
});
+2 -2
View File
@@ -18,13 +18,13 @@ declare module "redux-bootstrap" {
}
interface BootstrapResult {
store: Redux.Store;
store: Redux.Store<any>;
history: ReactRouterRedux.ReactRouterReduxHistory;
root: JSX.Element;
}
interface ReducersOption {
[index: string]: Redux.Reducer;
[index: string]: Redux.Reducer<any>;
}
export default function bootstrap(options: BootstrapOptions): BootstrapResult;
@@ -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<any>;
class CounterApp extends Component<any, any> { };
class Provider extends Component<{ store: any }, any> { };
+2 -2
View File
@@ -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<any>): IDevTools
export function persistState(debugSessionKey: string): Function
var factory: { instrument(): Function }
var factory: { instrument(): (opts: any) => any }
export default factory;
}
+7 -7
View File
@@ -192,7 +192,7 @@ declare module 'redux-form' {
*/
handleSubmit?(event:SyntheticEvent):void;
handleSubmit?(submit:(data:FormData, dispatch?:Dispatch)
handleSubmit?(submit:(data:FormData, dispatch?:Dispatch<any>)
=> Promise<any>|void):FormEventHandler;
/**
@@ -285,11 +285,11 @@ declare module 'redux-form' {
}
interface MapDispatchToPropsFunction {
(dispatch:Dispatch, ownProps?:any): any;
(dispatch:Dispatch<any>, ownProps?:any): any;
}
interface MapDispatchToPropsObject {
[name: string]: ActionCreator;
[name: string]: ActionCreator<any>;
}
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<any>, props:Object):
Promise<any>;
/**
@@ -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>): 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<any>;
/**
* 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<any>}):Reducer<any>;
}
}
+1 -1
View File
@@ -6,5 +6,5 @@
/// <reference path="../redux/redux.d.ts" />
declare module "redux-immutable" {
export function combineReducers(reducers : Object): Redux.Reducer;
export function combineReducers(reducers: Object): Redux.Reducer<any>;
}
+1 -1
View File
@@ -19,7 +19,7 @@ function counter(state: any, action: any) {
}
function loggingMiddleware() {
return (next: Redux.Dispatch) => (action: any) => {
return (next: Redux.Dispatch<any>) => (action: any) => {
console.log(action.type);
next(action);
};
@@ -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<any> = 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<any>, getState: Function) => {
dispatch({ type: "SECEOND_ACTION_TYPE", payload: "..." });
dispatch(someActionCreator());
})
+2 -5
View File
@@ -3,9 +3,8 @@
/// <reference path="../redux-actions/redux-actions.d.ts" />
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<any> {
return createAction('LIST_USERS',
() => {
return Promise.resolve([{ email: 'me@definitely.typed' }]);
});
}
+12 -7
View File
@@ -1,18 +1,23 @@
// Type definitions for redux-promise v0.5.3
// Project: https://github.com/acdlite/redux-promise
// Definitions by: Rogelio Morrell Caballero <https://github.com/molekilla>
// Definitions by: Rogelio Morrell Caballero <https://github.com/molekilla>, Kaur Kuut <https://github.com/xStrom>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference path="../redux/redux.d.ts" />
declare namespace Redux {
type PromiseAction<S> = (dispatch: Redux.Dispatch<S>, getState?: () => S) => any;
interface Dispatch<S> {
<R>(asyncAction: PromiseAction<S>): R;
}
}
declare namespace ReduxPromise {
export interface Promise extends Redux.Middleware {}
export interface PromiseInterface {
<T>(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;
}
+1 -1
View File
@@ -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<any>): IO;
export function runSaga(iterator: Iterable<any>,
io: IO,
+7 -8
View File
@@ -2,11 +2,10 @@
/// <reference path="../redux/redux.d.ts" />
/// <reference path="../express/express.d.ts" />
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<any> = 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<any, any, any> {
// 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>): 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<any, any, any> {
return function (dispatch: Dispatch<any>, getState: () => any): any {
if (!getState().sandwiches.isShopOpen) {
// You don’t have to return Promises, but it’s a handy convention
+15 -9
View File
@@ -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 <https://github.com/tkqubo>
// Definitions by: Qubo <https://github.com/tkqubo>, Kaur Kuut <https://github.com/xStrom>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference path="../redux/redux.d.ts" />
declare namespace ReduxThunk {
export interface Thunk extends Redux.Middleware {}
export interface ThunkInterface {
<T>(dispatch: Redux.Dispatch, getState?: () => T): any;
}
declare namespace Redux {
type ThunkAction<R, S, E> = (dispatch: Dispatch<S>, getState: () => S, extraArgument: E) => R;
interface Dispatch<S> {
<R, E>(asyncAction: ThunkAction<R, S, E>): 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;
}