Vue3+ts+eslint报错记录及解决:warning Unexpected any. Specify a different type、warning Delete `·` 、Missing return type on function、Require statement not part of import statement、Unnecessary escape character

一、警告:warning Unexpected any. Specify a different type @typescript-eslint/no-explicit-any

  解决方案:关闭any类型的警告。

// 在 .eslintrc.js文件中找到rules 添加一行代码即可
"@typescript-eslint/no-explicit-any": ["off"]

  添加完成之后,重新运行项目即可。

二、使用eslint时总是提醒warning Delete `·` prettier/prettier或者405:15 warning Insert `⏎·····` prettier

  解决方案:可执行代码即可

npm run lint --fix

  执行之后会自动修改,我这里看到把单引号改成了双引号。

三、warning: Missing return type on function  (@typescript-eslint/explicit-module-boundary-types) at src\main.ts:32:8

  解决方案:在.eslintrc.js文件里添加规则禁用ta

"rules": {
    "@typescript-eslint/explicit-module-boundary-types": "off"
},

四、Require statement not part of import statement.(@typescript-eslint/no-var-requires)

// 当在 vue.config.js 中:
const path = require('path')

// 提示报错:
Require statement not part of import statement.(@typescript-eslint/no-var-requires)

  解决方案:在 .eslintrc.js中的 rules 属性新增以下内容:

rules: {
    '@typescript-eslint/no-var-requires': 0
}

五、Unnecessary escape character: \/ no-useless-escape

  通常见与写正则时报错:

   79:17  error    Unnecessary escape character: \/  no-useless-escape
   79:21  error    Unnecessary escape character: \[  no-useless-escape
  131:22  warning  Insert `,`                        prettier/prettier
  132:4   warning  Insert `,`                        prettier/prettier

$ Unnecessary escape character: - no-useless-escape

禁用不必要的转义字符; \-

  不必要的转义字符,上面都给你提示了,改一下就行。

const reg = /[\/{}\[\]#%?\\]+/

// 不必要的转义字符去掉
const reg = /[/{}[\]#%?\\]+/
原文地址:https://www.cnblogs.com/goloving/p/15421496.html