$ npx create-react-app "프로젝트명" --template typescript
//tsconfig.json
{
"compilerOptions": {
"baseUrl": "./src", // 이 부분 추가, 기본 경로 설정
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noFallthroughCasesInSwitch": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react-jsx"
},
"include": ["src"]
}
//package.json
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
$ npm i -D eslint // 설치
$ npx eslint --init // 설정
아래와 같이 설정
// eslintrc.json
{
"env": {
"browser": true,
"es2021": true
},
"extends": [
"plugin:react/recommended",
"standard-with-typescript",
],
"overrides": [],
"parserOptions": {
"ecmaVersion": "latest",
"project": "tsconfig.json",
"sourceType": "module"
},
"plugins": ["react", "@typescript-eslint"],
"rules": {
"react/react-in-jsx-scope": ["off"],
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/triple-slash-reference": "off"
}
}
"parserOptions": {
"tsconfigRootDir": "파일경로"
}
npm i -D prettier eslint-config-prettier eslint-plugin-prettier
// .prettierrc.json
{
"singleQuote": true,
"semi": true,
"tabWidth": 2
}
// .eslintrc.json
{
"env": {
"browser": true,
"es2021": true
},
"extends": [
"plugin:react/recommended",
"standard-with-typescript",
"plugin:prettier/recommended"
],
"overrides": [],
"parserOptions": {
"ecmaVersion": "latest",
"project": "tsconfig.json",
"sourceType": "module"
},
"plugins": ["react", "@typescript-eslint", "prettier"],
"rules": {
"prettier/prettier": "error",
"react/react-in-jsx-scope": ["off"],
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/triple-slash-reference": "off"
}
}
{
...
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
},
"eslint.alwaysShowStatus": true,
"eslint.enable": true,
"eslint.validate": [
"javascript",
"javascriptreact",
"typescript",
"typescriptreact"
],
...
}