diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 342e92d5d..66c07e803 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -54,10 +54,6 @@ npm run lint Please open an issue with a proposal for a new feature or refactoring before starting on the work. We don't want you to waste your efforts on a pull request that we won't want to accept. -###Style - -[reactjs](https://github.com/reactjs) is trying to keep a standard style across its various projects, which can be found over in [eslint-config-reactjs](https://github.com/reactjs/eslint-config-reactjs). If you have a style change proposal, it should first be proposed there. If accepted, we will be happy to accept a PR to implement it here. - ## Submitting Changes * Open a new issue in the [Issue tracker](https://github.com/reactjs/react-redux/issues). diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 000000000..9c1da0490 --- /dev/null +++ b/index.d.ts @@ -0,0 +1,70 @@ +import { ComponentClass, Component, StatelessComponent } from 'react'; +import { Store, Dispatch, ActionCreator } from 'redux'; + +interface ComponentDecorator { + (component: StatelessComponent|ComponentClass): ComponentClass; +} + +/** + * Following 5 functions cover all possible ways connect could be invoked + * + * - State: Redux state interface (the same one used by Store) + * - TOwnProps: Props passed to the wrapping component + * - TStateProps: Result of MapStateToProps + * - TDispatchProps: Result of MapDispatchToProps + */ +function connect(): ComponentDecorator<{ dispatch: Dispatch } & TOwnProps, TOwnProps>; + +function connect( + mapStateToProps: FuncOrSelf>, +): ComponentDecorator } & TOwnProps, TOwnProps>; + +function connect( + mapStateToProps: FuncOrSelf>, + mapDispatchToProps: FuncOrSelf | MapDispatchToPropsObject & TDispatchProps> +): ComponentDecorator; + +function connect( + mapStateToProps: null, + mapDispatchToProps: FuncOrSelf | MapDispatchToPropsObject & TDispatchProps> +): ComponentDecorator; + +function connect( + mapStateToProps: FuncOrSelf>, + mapDispatchToProps: FuncOrSelf| MapDispatchToPropsObject & TDispatchProps>, + mergeProps: MergeProps, + options?: Options +): ComponentDecorator; + +interface MapDispatchToPropsObject { + [name: string]: ActionCreator; +} + +interface MapStateToProps { + (state: State, ownProps: TOwnProps): TStateProps; +} + +interface MapDispatchToPropsFunction { + (dispatch: Dispatch, ownProps: TOwnProps): TDispatchProps; +} + +interface MergeProps { + (stateProps: TStateProps, dispatchProps: TDispatchProps, ownProps: TOwnProps): TMergeProps; +} + +interface Options { + pure?: boolean; + withRef?: boolean; +} + +type FuncOrSelf = T | (() => T); + +/** + * Typescript does not support generic components in tsx yet in an intuïtive way which is the reason we avoid a + * generic parameter in Store here by using any as the type + */ +export interface ProviderProps { + store: Store; +} + +export class Provider extends Component { } diff --git a/package.json b/package.json index 576522b83..af832b523 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,7 @@ "version": "4.4.5", "description": "Official React bindings for Redux", "main": "./lib/index.js", + "typings": "./index.d.ts", "scripts": { "build:lib": "babel src --out-dir lib", "build:umd": "cross-env NODE_ENV=development webpack src/index.js dist/react-redux.js", @@ -22,7 +23,8 @@ "files": [ "dist", "lib", - "src" + "src", + "index.d.ts" ], "keywords": [ "react",