/** * 实现参考链接: * https://github.com/DefinitelyTyped/DefinitelyTyped/issues/9951 * * ComponentClass 使用react, 保持和 taro-component 组件库一致 * 也可以在 Taro 中重新声明 * */ import { ComponentClass } from 'react'; import { Component, } from '@tarojs/taro'; import { Action, AnyAction, Store, Dispatch } from 'redux'; export type InferableComponentEnhancerWithProps = >(component: IComponent) => IComponent export interface IConnect { ( mapStateToProps?: MapStateToPropsParam, mapDispatchToProps?: MapDispatchToPropsParam, ): InferableComponentEnhancerWithProps } export const connect: IConnect interface MapStateToProps { (state: State, ownProps: TOwnProps): TStateProps; } interface MapStateToPropsFactory { (initialState: State, ownProps: TOwnProps): MapStateToProps; } type MapStateToPropsParam = MapStateToPropsFactory | MapStateToProps | null | undefined; interface MapDispatchToPropsFunction { (dispatch: Dispatch, ownProps: TOwnProps): TDispatchProps; } type MapDispatchToProps = MapDispatchToPropsFunction | TDispatchProps; interface MapDispatchToPropsFactory { (dispatch: Dispatch, ownProps: TOwnProps): MapDispatchToProps; } type MapDispatchToPropsParam = MapDispatchToPropsFactory | MapDispatchToProps; interface MergeProps { (stateProps: TStateProps, dispatchProps: TDispatchProps, ownProps: TOwnProps): TMergedProps; } export interface ProviderProps { store: Store; } export class Provider extends Component, any> { } /** * A hook to access the redux store's state. This hook takes a selector function * as an argument. The selector is called with the store state. * * This hook takes an optional equality comparison function as the second parameter * that allows you to customize the way the selected state is compared to determine * whether the component needs to be re-rendered. * * If you do not want to have to specify the root state type for whenever you use * this hook with an inline selector you can use the `TypedUseSelectorHook` interface * to create a version of this hook that is properly typed for your root state. * * @param selector the selector function * @param equalityFn the function that will be used to determine equality * * @returns the selected state * * @example * * import React from 'react' * import { useSelector } from 'react-redux' * import { RootState } from './store' * * export const CounterComponent = () => { * const counter = useSelector((state: RootState) => state.counter) * return
{counter}
* } */ export function useSelector( selector: (state: TState) => TSelected, equalityFn?: (left: TSelected, right: TSelected) => boolean ): TSelected; /** * A hook to access the redux store. * * @returns the redux store * * @example * * import React from 'react' * import { useStore } from 'react-redux' * * export const ExampleComponent = () => { * const store = useStore() * return
{store.getState()}
* } */ export function useStore(): Store; /** * A hook to access the redux `dispatch` function. * * Note for `redux-thunk` users: the return type of the returned `dispatch` functions for thunks is incorrect. * However, it is possible to get a correctly typed `dispatch` function by creating your own custom hook typed * from the store's dispatch function like this: `const useThunkDispatch = () => useDispatch();` * * @returns redux store's `dispatch` function * * @example * * import React, { useCallback } from 'react' * import { useDispatch } from 'react-redux' * * export const CounterComponent = ({ value }) => { * const dispatch = useDispatch() * return ( *
* {value} * *
* ) * } */ // NOTE: the first overload below and note above can be removed if redux-thunk typings add an overload for // the Dispatch function (see also this PR: https://github.com/reduxjs/redux-thunk/pull/247) export function useDispatch>(): TDispatch; export function useDispatch
(): Dispatch;