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
来消除此错误,但是我仍然想要对此做一个解释,并寻求一个永久性的解决方案,这样我就不会出现错误 Error 了。
答案 0 :(得分:2)
前段时间,我有一个类似的案例,并通过将@typescript-eslint/parser
安装为devDependency并将其包含在eslint config中来解决它:
"extends": [..., "@typescript-eslint/parser"],