再来一次,又是一个月,又是一个Resharper,它在使用Node和@type时,似乎破坏了TypeScript中的一切。
我正在使用TypeScript、React和Redux,所以使用npm包redux-actions和@types/redux-actions进行各种强类型的ReduxActions
我的代码看起来是:
const pageReducer = handleActions<IPageState, number | string>({
[actionTypes.doSomething]: (state: IPageState, action: Action<string>): IPageState => {
// some code to manipulate the state
return {}; // returning the manipulated state
},
[actionTypes.doSomethingElse]: (state: IPageState, action: Action<number>): IPageState => {
// some code to manipulate the state
return {}; // returning the manipulated state
}
}, initialState()); // initial state function which returns initial state objectIPageState是一个具有多种属性的接口。
所有的东西都是通过webpack编写和捆绑的,运行起来很有魅力,所以代码没有问题。在过去的两年里,我们一直在使用这种模式,而且运作良好。
然而,随着最新的Resharper更新(版本2017.3),它现在抱怨handleActions<IPageState, number | string>
非类型化函数调用可能不接受类型参数
我注意到Resharper似乎在查看文件/node_modules/redux-actions/lib/index.js,以获得它对所有内容的定义,而不是查看/node_modules/@types/redux-actions/index.d.ts文件。因此,如果我删除lib文件夹,所有的Resharper错误都会消失。
是否要告诉Resharper只需忽略lib文件夹?我不能只是删除它,因为当执行一个新的安装,然后文件夹将重新出现。
发布于 2018-03-20 11:17:17
这被认为是Resharper中的一个bug,现在已经修复了。https://youtrack.jetbrains.com/issue/RSRP-467712
如果您下载Resharper的最新版本,这个问题现在就解决了。
发布于 2018-01-31 17:59:45
我也有同样的问题。到目前为止,我发现的唯一方法是为我的一个react组件顶部的类型定义添加一个三重斜杠指令(我把它放在app.tsx中,这是我的应用程序的主要反应组件)。
/// <reference path="./../../node_modules/@types/react/index.d.ts"/>将其添加到源中的单个文件中,似乎足以修复错误的R#错误项目。不太理想,我也不知道为什么要起作用,但到目前为止,它似乎已经解决了这个问题。
https://stackoverflow.com/questions/47927686
复制相似问题