[Unit 5] TypeScript 설치

JeongYeon·2023년 5월 30일
0

[SEB FE]section4

목록 보기
11/16
post-thumbnail

TypeScript 환경 구성

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
  1. 프로젝트 폴더 밑에 .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',
  },
};
profile
프론트엔드 개발자 될거야( ⸝⸝•ᴗ•⸝⸝ )੭⁾⁾

0개의 댓글

관련 채용 정보