【发布时间】:2020-06-21 12:59:29
【问题描述】:
我有问题要问你!我在 typeScript 上迁移了我的整个应用程序,但在 compose 功能上遇到了一些困难......(不用担心我已经修复的其他任何问题,除了 compose())
使用compose(...)(没有“任何”)我得到以下信息:
没有重载匹配这个调用。 Overload 1 of 2, '(props: Readonly): Route',给出了以下错误。 类型“未知”不可分配给类型“ComponentClass |功能组件 |组件类,任意> |函数组件<...> |不明确的'。 类型“未知”不可分配给类型“FunctionComponent>”。 Overload 2 of 2, '(props: RouteProps, context?: any): Route',给出了以下错误。 类型“未知”不可分配给类型“ComponentClass |功能组件 |组件类,任意> |函数组件<...> |不明确的'。 类型“未知”不可分配给类型“FunctionComponent>”。 TS2769
这就是为什么我想替换它并输入它。
这是我的代码:
/container.ts
//@ts-ignore
import { connect } from "react-redux";
import { compose, AnyAction, Dispatch } from "redux";
import { withRouter } from "react-router-dom";
import { getProfile, updateProfile } from "../../../services/clients/user";
import { updateUserInitial } from "../../../actions/initialUser";
import { IStoreState } from "../../typeScriptInclude";
import { ThunkDispatch } from "redux-thunk";
import { Profile } from "./component/utilities/includeTypeScript";
import { IEditAccountProps as Props } from './component/EditAccount';
interface IupDateWalterInitailUserPropsType {
walterUser: {
first_name: string;
last_name: string;
};
}
interface IMapStateToProps{
isConnect: boolean;
walterUser: any;
upDateProfile: any;
}
interface IMapDispatchToProps{
upDateWalterInitailUser: any;
}
const mapStateToProps = (state: IStoreState): IMapStateToProps => {
return {
isConnect: state.isConnect,
walterUser: getProfile(),
upDateProfile: (data: Profile) => updateProfile(data)
};
};
type ApplicationDispatch = ThunkDispatch<IStoreState, void, AnyAction> &
Dispatch;
const mapDispatchToProps = (
dispatch: ApplicationDispatch,
): IMapDispatchToProps => ({
upDateWalterInitailUser: (form: IupDateWalterInitailUserPropsType) =>
dispatch(updateUserInitial(form))
});
export default compose<any>(
withRouter,
connect(
mapStateToProps,
mapDispatchToProps
)
);
/index.ts
import EditAccount from "./component/EditAccount";
import container from './container';
export default container(EditAccount);
事情是我尝试了很多东西来输入它,但无能为力...... 我试过了
// Which props define our new component : IProps - IInjectedProps
type ContainerProps = Omit<Props, keyof InjectedProps>;
export default compose<Props, ContainerProps>(
withRouter,
connect(
mapStateToProps,
mapDispatchToProps
)
);
我起飞 withRouter 但我得到以下信息:
预期 2 个参数,但得到 1 个。TS2554
显然,但为什么它不适用于我的第一个解决方案......需要了解
谢谢大家最好的问候。
【问题讨论】:
-
我认为您应该将组合功能应用于组件。你想在这里
connect什么组件? -
我在帖子中添加了更多详细信息;)但要> EditAccount
-
您在执行
compose(...)时是否遇到语法错误?如果是这样,错误是什么?如果不是,为什么要输入它? -
对不起,我一开始不明白你的意思,但我明白了:
No overload matches this call. Overload 1 of 2,... Type 'unknown' is not assignable to type 'ComponentClass<any, any> | FunctionComponent<any> | ComponentClass<RouteComponentProps<any, StaticContext, PoorMansUnknown>, any> | FunctionComponent<...> | undefined'. Type 'unknown' is not assignable to type 'FunctionComponent<RouteComponentProps<any, StaticContext, PoorMansUnknown>>'. TS2769
标签: reactjs typescript redux