Typescript为自己的编译提供了错误
我的代码:Typescript为自己的编译提供了错误,typescript,webpack,bind,ts-loader,Typescript,Webpack,Bind,Ts Loader,我的代码: addMouseOverListenerForNavItems() { this.navList.addEventListener('mouseover', this.mouseOverListener.bind(this)); } mouseOverListener(e) { const closestNavItem: HTMLElement = e.target.closest(".js-mainbar__navitem"); cle
addMouseOverListenerForNavItems() {
this.navList.addEventListener('mouseover', this.mouseOverListener.bind(this));
}
mouseOverListener(e) {
const closestNavItem: HTMLElement = e.target.closest(".js-mainbar__navitem");
clearTimeout(this.closeTimer);
this.openTimer = setTimeout(() => {
this.openFlyout(closestNavItem);
}, this.flyoutDelayMs);
}
按类型脚本编译的代码:
Menu.prototype.mouseOverListener = function (e) {
var _this = this;
var closestNavItem = e.target.closest(".js-mainbar__navitem");
clearTimeout(this.closeTimer);
this.openTimer = setTimeout(function () {
_this.openFlyout(closestNavItem);
}, this.flyoutDelayMs);
};
错误:
60:13错误将“this”意外别名为局部变量@typescript eslint/no此别名
59和60.5行=
Menu.prototype.mouseOverListener = function (e) {
var _this = this;
我应该做什么来修复此错误?我想我已经正确地使用了箭头功能
.eslintrc.js
module.exports = {
parser: '@typescript-eslint/parser', // Specifies the ESLint parser
extends: [
'plugin:@typescript-eslint/recommended', // Uses the recommended rules from the @typescript-eslint/eslint-plugin
],
parserOptions: {
ecmaVersion: 2018, // Allows for the parsing of modern ECMAScript features
sourceType: 'module', // Allows for the use of imports
},
rules: {
"curly": 1,
"@typescript-eslint/explicit-function-return-type": [0],
"@typescript-eslint/no-explicit-any": [0],
"ordered-imports": [0],
"object-literal-sort-keys": [0],
"max-len": [1, 120],
"new-parens": 1,
"no-bitwise": 1,
"no-cond-assign": 1,
"no-trailing-spaces": 0,
"eol-last": 1,
"func-style": ["error", "declaration", { "allowArrowFunctions": true }],
"semi": 1,
"no-var": 0
},
};
控制台错误
我通过添加
enforce: "pre"
到网页上
为了安全起见,您可以使用强制:“pre”部分检查源文件,而不是由其他加载程序(如babel加载程序)修改:
来源:您是否以某种方式将以前生成的javascript文件传递到transpiler/linter中?检查应该只应用于typescript文件,因此您描述的内容很奇怪。当你看到这个错误时,你能解释一下吗?你运行了什么命令?当我运行“npm start”时,我在chrome控制台上看到了它。在您的建议“exclude”之后,我在tsconfig.json中添加了exclude参数:[“node_modules”,“build”,“dist”,“src/***/.js”]仍然不起作用。您可以看到,错误来自linter。我已将这些#Ignore build file./build/*./dist/*添加到.eslintinignore中。仍然给出这些错误。编译后的javascript文件命名为menu.ts是否正常?(我在上面添加了截图)