自分用メモです。
必要パッケージインストール
-
yarn add typescript @types/node// TypeScript導入 -
yarn add -D eslint @typescript-eslint/parser @typescript-eslint/eslint-plugin prettier eslint-config-prettier eslint-plugin-prettier// ESLint + Prettier導入 -
yarn add json-loader// JSON読むやつ
設定ファイル生成・編集
package.jsonのscriptsに以下を追加
"scripts": {
"tsc-init": "tsc --init",
"watch": "tsc --watch",
"build": "tsc"
}
tsconfig.jsonの生成
yarn tsc-init- tsconfig.json内の以下を変更
- targetを
es2015 - outDirを
./.dist/ - rootDirを
./src/ - types(配列)に
nodeを追加
- targetを
ESLint + Prettierの設定
-
eslint --init- TypeScriptを使用しないを選択
- .prettierrcに
"singleQuote": trueを追加 - .eslintrc.jsonに以下を追加
{
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:prettier/recommended",
"prettier/@typescript-eslint"
],
"plugins": ["@typescript-eslint"],
"parser": "@typescript-eslint/parser"
}
あとは全コードをTypeScript化しておわり!