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