Typescript 使用babel eslint解析进行类型脚本转换
在将ESLint引入现有的Typescript代码库之后,我遇到了一些解析错误 我已经修复了大部分lint错误,但是由于解析器抛出了很多类似这样的错误,所以我修复了babel eslintTypescript 使用babel eslint解析进行类型脚本转换,typescript,babeljs,eslint,babel-eslint,Typescript,Babeljs,Eslint,Babel Eslint,在将ESLint引入现有的Typescript代码库之后,我遇到了一些解析错误 我已经修复了大部分lint错误,但是由于解析器抛出了很多类似这样的错误,所以我修复了babel eslint 23:32 error Parsing error: Unexpected token, expected "," 21 | return state.set( 22 | 'callsInProgress', > 23 |
23:32 error Parsing error: Unexpected token, expected ","
21 | return state.set(
22 | 'callsInProgress',
> 23 | (state.callsInProgress as any).filter(i => i !== action.payload)
| ^
24 | );
25 | }
26 | case actions.API_RESET: {
我认为这是因为巴贝尔不理解类型转换
我如何通过解析器获得这些信息
我的babel配置如下:
module.exports = {
presets: ['@babel/preset-env', '@babel/preset-react', '@babel/preset-typescript'],
plugins: ['@babel/plugin-proposal-class-properties', '@babel/plugin-transform-runtime', '@babel/plugin-transform-typescript']
};
拥有一个使用巴别塔、eslint和我自己的项目
我建议您停止使用eslint-babel
,改用@typescript-eslint
/
是由Tslint的开发人员启动的项目(现已弃用)。它完美地过滤了打字脚本代码
以下是我的eslint安装的npm软件包示例:
"@typescript-eslint/eslint-plugin": "^2.34.0",
"@typescript-eslint/parser": "^2.34.0",
"eslint": "^5.16.0",
"eslint-plugin-import": "^2.21.2",
"eslint-plugin-jsx-a11y": "^6.3.0",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-react": "^7.20.0",
my.eslintrc
的示例:
module.exports = {
root: true,
parser: '@typescript-eslint/parser',
plugins: [
'@typescript-eslint',
'eslint-plugin-node',
],
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
],
parserOptions: {
"ecmaVersion": 2020
},
rules: {
"comma-dangle": ["error", {
"arrays": "always-multiline",
"objects": "always-multiline",
"imports": "always-multiline",
"exports": "always-multiline",
"functions": "always-multiline",
}],
},
env: {
es6: true,
browser: true,
node: true,
},
parserOptions: {
project: './tsconfig.json',
tsconfigRootDir: __dirname,
},
globals: {
"global": false,
"Promise": false,
},
};
注意:我不知道eslint-babel
是否能与@typescript-eslint
兼容,也许能兼容,你可以两者兼用。旁注:这是一个演员阵容,不是演员阵容。断言和强制转换不是一回事。谢谢。这就是我现在要去的地方,因为我发现了巴贝尔,和打字相比,它更难使用。