webpack typescript使用eslint

1、下载
	cnpm install -D @typescript-eslint/eslint-plugin @typescript-eslint/parser eslint

2、配置.eslintrc.json
	{
	  "parser":"@typescript-eslint/parser",
	  "plugins":["@typescript-eslint"],
	  "parserOptions": {
	    "project":"./tsconfig.json"
	  },
	  "extends":[
	    "plugin:@typescript-eslint/recommended"
	  ],
	  "rules":{
	    "@typescript-eslint/no-inferrable-types":"off"	 关掉去使用自动类型推断的报错
	  }
	}

3、命令执行
	eslint src --ext .js,.ts
	
	若报错:Parsing error: "parserOptions.project" has been set for @typescript-eslint/p...
		不能有相同的js和ts文件名

4、vscode插件自动修复
	在vscode插件->ESlint->扩展设置的settings.json中添加

在这里插入图片描述
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_43294560/article/details/114318373