我拼命工作了几个小时,试图为一个用created app创建的TypeScript项目启用衬里。
问题是上面建议的实现并没有给新创建的项目添加任何内容。
到目前为止,我已经尝试过:
tslint.json文件: {
"rules": {
"no-debugger": false,
"no-console": false,
"interface-name": false
},
"linterOptions": {
"exclude": [
"config/**/*.js", "node_modules/**/*.ts", "coverage/lcov-report/*.js"
]
},
"extends": [
"tslint:recommended",
"tslint-react",
"tslint-config-prettier"
]
}package.json添加一个lint脚本 "scripts": {
"lint": "tslint -c tslint.json src/**/*.{ts,tsx} --fix --format verbose"
}然后我试着运行yarn lint or npm run lint,但是没有任何文件可以从上面的任何一种方法中删除。
这是我的package.json文件:
{
"name": "myapp",
"version": "0.1.0",
"private": true,
"dependencies": {
"@types/jest": "^23.3.11",
"@types/node": "^10.12.18",
"@types/react": "^16.7.18",
"@types/react-dom": "^16.0.11",
"react": "^16.7.0",
"react-dom": "^16.7.0",
"react-scripts": "2.1.2",
"typescript": "^3.2.2"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject",
"lint": "tslint -c tslint.json src/**/*.{ts,tsx} --fix --format verbose",
"tslint-check": "tslint-config-prettier-check ./tslint.json"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": [
">0.2%",
"not dead",
"not ie <= 11",
"not op_mini all"
],
"devDependencies": {
"tslint": "^5.12.0",
"tslint-config-prettier": "^1.17.0",
"tslint-react": "^3.6.0"
}
}这是由npx创建反应应用程序项目-名称-类型记录自动生成的tsconfig.json。
{
"compilerOptions": {
"target": "es5",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "preserve"
},
"include": [
"src"
]
}有什么想法吗?
发布于 2019-01-04 22:23:40
我不得不经历同样的过程,弄清楚如何让TSLint和Pretter在CRA + TypeScript项目上工作。
我用一步一步地创建了这个,说明了如何相应地设置它。
简单地说,上面的解决方案是确保安装了适当的VSCode扩展和package.json中的适当依赖项,这样TSLint和更漂亮的TSLint都可以跟踪您的更改。
https://stackoverflow.com/questions/54034575
复制相似问题