typescript - eslint 给出误报
问题描述
我是 Webpack 的新手,遇到了 eslint 和 Typescript 的问题。eslint 告诉我我缺少函数的返回类型,但正如你所见,我有一个。
我已经@typescript-eslint/parser
在我的 .eslintrc 文件中包含了
// test-function.ts
7 function numberOne(): number {
8 return 1;
9 }
10
11 const numberTwo = (): number => 2;
12
13 console.log( numberTwo() - numberOne() );
// webpack.config.js
const path = require('path');
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
module.exports = {
context: __dirname,
mode: 'development',
watch: false,
entry: path.join( __dirname, 'src', 'index.ts'),
devtool: 'inline-source-map',
devServer: {
contentBase: './dist'
},
module: {
rules: [
{
enforce: 'pre',
test: /\.tsx?$/,
exclude: [
/node_modules/,
/declarations/
],
use: [
{
loader: 'eslint-loader',
options: {
configFile: '.eslintrc.json',
cache: false,
emitError: true,
failOnError: true,
fix: true
}
}
,
{
loader: 'ts-loader',
options: {
transpileOnly: true
}
}
]
},
]
},
plugins: [
new ForkTsCheckerWebpackPlugin(),
],
output: {
filename: 'main.js',
path: path.resolve(__dirname, './dist')
},
resolve: {
extensions: ['.wasm', '.ts', '.tsx', '.mjs', '.cjs', '.js', '.json']
}
};
// .eslintrc
{
"root": true,
"parser": "@typescript-eslint/parser",
"plugins": [
"@typescript-eslint"
],
"parserOptions": {
"sourceType": "module",
"ecmaVersion": 6,
"project": "./tsconfig.json"
},
"env": {
"es6": true,
"browser": true,
"worker": true
},
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
"plugin:@typescript-eslint/recommended-requiring-type-checking"
],
"ignorePatterns": [],
"rules": {
"@typescript-eslint/no-explicit-any": ["error"]
}
}
这就是错误的样子
7:1 warning Missing return type on function @typescript-eslint/explicit-function-return-type
10:19 warning Missing return type on function @typescript-eslint/explicit-function-return-type
任何帮助,将不胜感激。
解决方案
推荐阅读
- r - 在 r 中拆分分组的二项式数据
- scala - 如何更改 Rocket Chip 中非阻塞数据缓存的缓存行大小?
- laravel - 检测到 Laravel 全局中间件但未更改模型记录
- python - 调整后的相互信息
- openshift - 关于 cloudfoundry 和 openshift
- java - Spring Boot 查询构建器机制如何工作?(Crud 存储库)
- c++ - 输入验证以过滤掉字符、字符串和一系列整数
- linux - 是否可以在远程服务器上运行 Netlogo?
- javascript - 使用 fetch api 上传文件 & 获取文件上传数据
- javascript - 在 Sweetalert 显示成功的消息通知