From 387387b1431b70678c6e81766ba7f220fd779efc Mon Sep 17 00:00:00 2001 From: tkqubo Date: Thu, 24 Sep 2015 00:47:16 +0900 Subject: [PATCH] Add more detailed typings about connect arguments --- react-redux/react-redux-tests.tsx | 3 +- react-redux/react-redux.d.ts | 52 +++++++++++++++++++++++++++---- 2 files changed, 47 insertions(+), 8 deletions(-) diff --git a/react-redux/react-redux-tests.tsx b/react-redux/react-redux-tests.tsx index 6e883d1f0..9bd662295 100644 --- a/react-redux/react-redux-tests.tsx +++ b/react-redux/react-redux-tests.tsx @@ -68,10 +68,9 @@ const targetEl = document.getElementById('root'); React.render(( {() => } - + ), targetEl); - // // API // https://github.com/rackt/react-redux/blob/master/docs/api.md diff --git a/react-redux/react-redux.d.ts b/react-redux/react-redux.d.ts index 454399f83..f1ef5458e 100644 --- a/react-redux/react-redux.d.ts +++ b/react-redux/react-redux.d.ts @@ -4,25 +4,65 @@ // Definitions: https://github.com/borisyankov/DefinitelyTyped /// +/// declare module "react-redux" { import { Component } from 'react'; + import { Store, Dispatch, ActionCreator } from 'redux'; export interface ClassDecorator { (target: TFunction): TFunction|void; } - export function connect(...functions: Function[]): ClassDecorator; + /** + * Connects a React component to a Redux store. + * @param mapStateToProps + * @param mapDispatchToProps + * @param mergeProps + * @param options + */ + export function connect(mapStateToProps?: MapStateToProps, + mapDispatchToProps?: MapDispatchToPropsFunction|MapDispatchToPropsObject, + mergeProps?: MergeProps, + options?: Options): ClassDecorator; - export interface Store { - subscribe: Function; - dispatch: Function; - getState: Function; + interface MapStateToProps { + (state: any, ownProps?: any): any; + } + + interface MapDispatchToPropsFunction { + (dispatch: Dispatch, ownProps?: any): any; + } + + interface MapDispatchToPropsObject { + [name: string]: ActionCreator; + } + + interface MergeProps { + (stateProps: any, dispatchProps: any, ownProps: any): any; + } + + interface Options { + /** + * If true, implements shouldComponentUpdate and shallowly compares the result of mergeProps, + * preventing unnecessary updates, assuming that the component is a “pure” component + * and does not rely on any input or state other than its props and the selected Redux store’s state. + * Defaults to true. + * @default true + */ + pure: boolean; } export interface Property { - store: Store; + /** + * The single Redux store in your application. + */ + store?: Store; + children?: Function; } + /** + * Makes the Redux store available to the connect() calls in the component hierarchy below. + */ export class Provider extends Component { } }