![](/img/trans.png)
[英]Typescript error 'argument of type is not assignable to parameter of type'
[英]Typescript error: Argument type is not assignable to parameter type, but they are the same
请告诉我,为什么会出现错误?
interface IAction {
readonly type: "GET_CURRENT_DATE" | "SET_CURRENT_DATE";
}
interface IDispatch {
(param: IAction): void;
}
export const getCurrentDate = () => (dispatch: IDispatch) => {
dispatch({type: "GET_CURRENT_DATE"});
};
错误:参数类型{type:string}无法分配给参数类型IAction
但是{type:“ GET_CURRENT_DATE”}与IAction相同
UPD:在package.json中->“ typescript”:“ ^ 2.6.2”。 使用webpack“ ts-loader”进行编译也没有错误,但是在我的IDE(PhpStorm 2017.3)中,我看到此错误消息。
我已经在IDE(WebStorm)的“设置|语言和框架| Typescript”中更改了此设置,然后将选中的“ TypeScript语言服务”更改为“也为没有tsconfig.json的项目”。 现在可以了
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.