|
| 1 | +// Type definitions for react-redux 4.4.0 |
| 2 | +// Project: https://github.com/rackt/react-redux |
| 3 | +// Definitions by: Qubo <https://github.com/tkqubo>, Sean Kelley <https://github.com/seansfkelley> |
| 4 | +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped |
| 5 | + |
| 6 | +/// <reference types="react" /> |
| 7 | +/// <reference types="redux" /> |
| 8 | + |
| 9 | +import { ComponentClass, Component, StatelessComponent, ReactNode } from 'react'; |
| 10 | +import { Store, Dispatch, ActionCreator } from 'redux'; |
| 11 | + |
| 12 | +interface ComponentDecorator<TOriginalProps, TOwnProps> { |
| 13 | + (component: ComponentClass<TOriginalProps> | StatelessComponent<TOriginalProps>): ComponentClass<TOwnProps>; |
| 14 | +} |
| 15 | + |
| 16 | +/** |
| 17 | + * Decorator that infers the type from the original component |
| 18 | + * |
| 19 | + * Can't use the above decorator because it would default the type to {} |
| 20 | + */ |
| 21 | +export interface InferableComponentDecorator { |
| 22 | + <P, TComponentConstruct extends (ComponentClass<P> | StatelessComponent<P>)>(component: TComponentConstruct): TComponentConstruct; |
| 23 | +} |
| 24 | + |
| 25 | +/** |
| 26 | + * Connects a React component to a Redux store. |
| 27 | + * |
| 28 | + * - Without arguments, just wraps the component, without changing the behavior / props |
| 29 | + * |
| 30 | + * - If 2 params are passed (3rd param, mergeProps, is skipped), default behavior |
| 31 | + * is to override ownProps (as stated in the docs), so what remains is everything that's |
| 32 | + * not a state or dispatch prop |
| 33 | + * |
| 34 | + * - When 3rd param is passed, we don't know if ownProps propagate and whether they |
| 35 | + * should be valid component props, because it depends on mergeProps implementation. |
| 36 | + * As such, it is the user's responsibility to extend ownProps interface from state or |
| 37 | + * dispatch props or both when applicable |
| 38 | + * |
| 39 | + * @param mapStateToProps |
| 40 | + * @param mapDispatchToProps |
| 41 | + * @param mergeProps |
| 42 | + * @param options |
| 43 | + */ |
| 44 | +export declare function connect(): InferableComponentDecorator; |
| 45 | + |
| 46 | +export declare function connect<TStateProps, TDispatchProps, TOwnProps>( |
| 47 | + mapStateToProps: MapStateToProps<TStateProps, TOwnProps>, |
| 48 | + mapDispatchToProps?: MapDispatchToPropsFunction<TDispatchProps, TOwnProps> | MapDispatchToPropsObject |
| 49 | +): ComponentDecorator<TStateProps & TDispatchProps, TOwnProps>; |
| 50 | + |
| 51 | +export declare function connect<TStateProps, TDispatchProps, TOwnProps>( |
| 52 | + mapStateToProps: MapStateToProps<TStateProps, TOwnProps>, |
| 53 | + mapDispatchToProps: MapDispatchToPropsFunction<TDispatchProps, TOwnProps> | MapDispatchToPropsObject, |
| 54 | + mergeProps: MergeProps<TStateProps, TDispatchProps, TOwnProps>, |
| 55 | + options?: Options |
| 56 | +): ComponentDecorator<TStateProps & TDispatchProps, TOwnProps>; |
| 57 | + |
| 58 | +interface MapStateToProps<TStateProps, TOwnProps> { |
| 59 | + (state: any, ownProps?: TOwnProps): TStateProps; |
| 60 | +} |
| 61 | + |
| 62 | +interface MapDispatchToPropsFunction<TDispatchProps, TOwnProps> { |
| 63 | + (dispatch: Dispatch, ownProps?: TOwnProps): TDispatchProps; |
| 64 | +} |
| 65 | + |
| 66 | +interface MapDispatchToPropsObject { |
| 67 | + [name: string]: ActionCreator; |
| 68 | +} |
| 69 | + |
| 70 | +interface MergeProps<TStateProps, TDispatchProps, TOwnProps> { |
| 71 | + (stateProps: TStateProps, dispatchProps: TDispatchProps, ownProps: TOwnProps): TStateProps & TDispatchProps; |
| 72 | +} |
| 73 | + |
| 74 | +interface Options { |
| 75 | + /** |
| 76 | + * If true, implements shouldComponentUpdate and shallowly compares the result of mergeProps, |
| 77 | + * preventing unnecessary updates, assuming that the component is a “pure” component |
| 78 | + * and does not rely on any input or state other than its props and the selected Redux store’s state. |
| 79 | + * Defaults to true. |
| 80 | + * @default true |
| 81 | + */ |
| 82 | + pure: boolean; |
| 83 | +} |
| 84 | + |
| 85 | +export interface ProviderProps { |
| 86 | + /** |
| 87 | + * The single Redux store in your application. |
| 88 | + */ |
| 89 | + store?: Store; |
| 90 | + children?: ReactNode; |
| 91 | +} |
| 92 | + |
| 93 | +/** |
| 94 | + * Makes the Redux store available to the connect() calls in the component hierarchy below. |
| 95 | + */ |
| 96 | +export declare class Provider extends Component<ProviderProps, {}> { } |
0 commit comments