TypeScript 프로젝트 환경 구성
- 프로젝트 폴더 생성
mkdir(폴더명)
cd(폴더명)
- 프로젝트 폴더 안으로 이동해 터미널에서
npm init -y
명령어 실행(프로젝트 초기화)
npm init -y
- TypeScript 설치
-npm install typescript --save-dev
- 프로젝트 루트 디렉토리에
tsconfig.json
파일 생성{ "compilerOptions": { "target": "es6", "module": "commonjs", "sourceMap": true, "outDir": "./dist" }, "include": [ "src/**/*" ] }
- src폴더에
index.ts
파일을 만들어 typescript코드 잓성
TypeScript ESLint, Prettier설정
1. 확장 프로그램인 ESLint와 Prettier 설치
2. 사용자 설정에 코드 넣기{ // ... "editor.codeActionsOnSave": { "source.fixAll.eslint": true }, "eslint.alwaysShowStatus": true, "eslint.workingDirectories": [ {"mode": "auto"} ], "eslint.validate": [ "javascript", "typescript" ], }
3. 에디터 설정에
format on save
가 체크되어있다면 해제하기
4. 필요한 프리셋, 라이브러리 설치npm i -D @babel/core @babel/preset-env @babel/preset-typescript @typescript-eslint/eslint-plugin @typescript-eslint/parser eslint prettier eslint-plugin-prettier
- 프로젝트 폴더 밑에
.eslintrc.js
파일을 만들고 코드 넣기module.exports = { root: true, env: { browser: true, node: true, jest: true, }, extends: [ 'plugin:@typescript-eslint/eslint-recommended', 'plugin:@typescript-eslint/recommended', ], plugins: ['prettier', '@typescript-eslint'], rules: { 'prettier/prettier': [ 'error', { singleQuote: true, tabWidth: 2, printWidth: 80, bracketSpacing: true, arrowParens: 'avoid', }, ], '@typescript-eslint/no-explicit-any': 'off', '@typescript-eslint/explicit-function-return-type': 'off', 'prefer-const': 'off', }, parserOptions: { parser: '@typescript-eslint/parser', }, };