2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

JavaScriptのプロジェクトをTypeScriptに移植する手順メモ

Last updated at Posted at 2020-02-05

自分用メモです。

必要パッケージインストール

  • 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を追加

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化しておわり!

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?