gpt4 book ai didi

Javascript 导入句柄未定义

转载 作者:搜寻专家 更新时间:2023-10-31 22:52:14 24 4
gpt4 key购买 nike

是否可以像下面的 switch case 示例语句那样捕获拼写错误?

首选方式是 eslinter 报告警告/错误。当前将 toString() 添加到 const 可用于在未定义的情况下在运行时引发 TypeError

actionTypes.js

export const UPDATE_REQUEST = 'UPDATE_REQUEST';

reducer.js

import * as types from '../constants/actionTypes';

export default function pouchdbReducer(state = {}, action) {
switch (action.type) {
case types.UPDDATE_REQUEST:
// there is a typo above and it evaluates to `undefined`
// this code would never be reached - how to make it an error
return Object.assign({}, state, {updated: true});
default:
return state;
}
}

更新:

@nikc.org 回答 eslint-plugin-importnamespace选项可用于检查此类错误。

这是带有配置和演示的小型存储库:

https://github.com/bmihelac/test-js-import-undefined/tree/eslint-plugin-import

eslint 配置的相关部分是:

"plugins": ["import"],
"rules": {
"import/namespace": [2],

最佳答案

免责声明,我是 tern-lint 的作者.

我建议你使用 tern-lint它能够报告诸如“未知属性”之类的错误。

您可以将此 linter 与命令或支持它的编辑器(Emacs、Atom、CodeMirror 或 Eclipse)一起使用。这是 Eclipse 的屏幕截图 tern.java

enter image description here

关于Javascript 导入句柄未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33809829/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com