TypeScript Settings

1. TypeScript ν”„λ‘œμ νŠΈ ν™˜κ²½ ꡬ성

1. ν”„λ‘œμ νŠΈ 폴더 생성

mkdir (폴더λͺ…)
cd (폴더λͺ…)

2. ν”„λ‘œμ νŠΈ 폴더 μ•ˆμ—μ„œ μ΄ˆκΈ°ν™”

npm init -y

3. TypeScript μ„€μΉ˜

npm install typescript --save-dev

4. ν”„λ‘œμ νŠΈ 루트 디렉토리에 .json 파일 생성 ν›„ λΆ™μ—¬λ„£κΈ°

//tsconfig.json
//compilerOptions λ‚΄μ˜ 속성은 μ»€μŠ€ν…€ κ°€λŠ₯
{
  "compilerOptions": {
    "target": "es6",
    "module": "commonjs",
    "sourceMap": true,
    "outDir": "./dist"
  },
  "include": [
    "src/**/*"
  ]
}

5. src 폴더 μ•ˆμ— .ts νŒŒμΌμ„ λ§Œλ“€μ–΄ TypeScript μ½”λ“œ μž‘μ„±

2. TypeScript ESLint와 Prettier μ„€μ •ν•˜κΈ°

1. ESLint μ„€μΉ˜ ν›„, settings.json에 μ•„λž˜ μ„€μ • 적용

{
  // ... 
  "editor.codeActionsOnSave": {
      "source.fixAll.eslint": true
  },
  "eslint.alwaysShowStatus": true,
  "eslint.workingDirectories": [
      {"mode": "auto"}
  ],
  "eslint.validate": [
      "javascript",
      "typescript"
  ],
}

2. VSCode 에디터 μ„€μ • 쀑 'format on save' μ„€μ • ν•΄μ œ

3. Prettier μ„€μΉ˜ ν›„, 프리셋과 라이브러리 μ„€μΉ˜

npm i -D @babel/core @babel/preset-env @babel/preset-typescript @typescript-eslint/eslint-plugin @typescript-eslint/parser eslint prettier eslint-plugin-prettier

4. ν”„λ‘œμ νŠΈ 폴더 밑에 .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',
  },
};

Last updated