LoginSignup
4
1

More than 5 years have passed since last update.

VSCodeでTypescriptの型定義ファイルを適用

Last updated at Posted at 2016-12-21

VSCodeにtypescriptの型定義を適用したときのメモ

環境

  • windows10
  • vscode1.8

フォルダ構成

project
  + .vscode
  + src
    - sample.ts
  - tsconfig.json
  - node_modules
    + @types

node.jsのインストール

Node.jsから6.9.2(LTS)をダウンロードしてインストール。

typescriptのインストール

npm install -g typescript

古くなるとVSCodeが警告を出してくれる

型定義ファイルのインストール

vscodeで開いているプロジェクトのルートフォルダにインストールする。
以下はreactの型定義ファイルの設定例

npm install @types/react

tsconfigの設定

es6の文法を使いたいのでes6をtrueに。
vscodeで開いているプロジェクトのルートフォルダに配置する。

tsconfig.json
{
    "compilerOptions": {
        "module": "commonjs",
        "target": "es6",
        "noImplicitAny": false,
        "sourceMap": false,
        "jsx": "react",
        "allowJs":true
    }
}

参考

Editing Typescript
typescript doc
特別なツール不要! TypeScript 2.0時代の型定義ファイルの取り扱い方

4
1
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
4
1