reactjs - ESLint:打字稿中未定义“部分”
问题描述
ESLint 无法识别Partial
打字稿,但编译后的模块没有给出任何错误。
const initialState: IAuthState = {
authenticated: false,
processing: false,
};
const authReducer = (state: IAuthState = initialState, action: any): IAuthState => {
const State = (newState: Partial<IAuthState>): IAuthState => ({...state, ...newState});
switch (action.type) {
case Actions.SIGN_IN_PROCESS_INITIATED:
return State({processing: true});
case Actions.SIGN_IN_PROCESS_FAILED:
return State({processing: false});
default:
return state;
}
};
我知道这可以被抑制,// eslint-disable-next-line no-undef
但我仍然想要一个解释和一个永久的解决方案,这样我就不会得到这个不是那么错误的错误。
解决方案
前段时间我有一个类似的案例,并通过安装@typescript-eslint/parser
为 devDependency 并将其包含在 eslint 配置中来修复它:
"extends": [..., "@typescript-eslint/parser"],
推荐阅读
- vb.net - 父子数据到内存中的父子列表结构
- javascript - 转换对象数组和连接对象值
- blazor - Blazer EditForm 提交不会触发 OnValidSubmit 和 OnInvalidSubmit 方法
- docker - 在 Swarm 模式下从 Docker 容器中获取服务列表
- python - 将自定义函数应用于数据框中的列
- python - Python电报机器人
- docker - 我如何验证 cassandra 是否正常工作
- java - Java 从 Internet Explorer 解压缩文件显示 0 个文件,但适用于其他浏览器
- laravel - 在 Laravel 中获取唯一的年份值
- python - 如何将行传递到pyspark udf