如何解决打字稿为自己的编译提供错误
我的代码:
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-this-alias 的意外别名
59 和 60.line =
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"
到 webpack。
为了安全起见,您可以使用enforce: 'pre' 部分来检查源文件,而不是被其他加载器(如babel-loader)修改:
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。