diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 000000000..b16bdbe18 --- /dev/null +++ b/index.d.ts @@ -0,0 +1,79 @@ + + +declare module "react-redux" { + import { ComponentClass, Component, StatelessComponent, ReactNode } from 'react'; + import { Store, Dispatch, ActionCreator } from 'redux'; + + interface ComponentDecorator { + (component: ComponentClass|StatelessComponent): ComponentClass; + } + + /** + * Decorator that infers the type from the original component + * + * Can't use the above decorator because it would default the type to {} + */ + export interface InferableComponentDecorator { + |StatelessComponent

)>(component: TComponentConstruct): TComponentConstruct; + } + + /** + * Following 3 functions cover all possible ways connect could be invoked + * + * - State: Redux state interface (the same one used by Store) + * - TStateProps: Result of MapStateToProps + * - TDispatchProps: Result of MapDispatchToProps + * - TOwnProps: Props passed to the wrapping component + */ + export function connect(): InferableComponentDecorator; + + export function connect( + mapStateToProps: MapStateToProps, + mapDispatchToProps?: MapDispatchToPropsFunction|MapDispatchToPropsObject + ): ComponentDecorator; + + export function connect( + mapStateToProps: MapStateToProps, + mapDispatchToProps: MapDispatchToPropsFunction|MapDispatchToPropsObject, + mergeProps: MergeProps, + options?: Options + ): ComponentDecorator; + + interface MapStateToProps { + (state: State, ownProps?: TOwnProps): TStateProps; + } + + /** + * State is not actually used here but included for consistency with Redux typings and MapStateToProps. + */ + interface MapDispatchToPropsFunction { + (dispatch: Dispatch, ownProps?: TOwnProps): TDispatchProps; + } + + /** + * Any since not every ActionCreator returns the same Action + */ + interface MapDispatchToPropsObject { + [name: string]: ActionCreator; + } + + interface MergeProps { + (stateProps: TStateProps, dispatchProps: TDispatchProps, ownProps: TOwnProps): TStateProps & TDispatchProps; + } + + interface Options { + pure?: boolean; + withRef?: boolean; + } + + /** + * 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; + children?: ReactNode; + } + + export class Provider extends Component { } +} \ No newline at end of file