LoginSignup
3
2

More than 5 years have passed since last update.

TypeScript型定義ファイルに躓いたメモ

Last updated at Posted at 2016-09-16

TypeScriptはじめました。
型定義ファイルを使うのにtypingsを入れたものの悩んだ点を大きいもの順に。

import

インストールした定義を使う。
typingsを使うなら/path/to/typings/index.d.tsを参照すればOK。

しかし、<reference ...の記載位置にハマる。
"use strict"より先に書くのが正解。

【追記:2016/10/02】そもそもTypeScriptに"use strict"は不要でした。

// 先に<reference ...を書く
/// <reference path="../../../typings/index.d.ts" />
// パスはそれぞれ合わせて

"use strict" 

// ここに <reference ...を書いたらダメ

定義の検索とインストール

検索

検索するとなにかみつかる

$ typings search xxx
Viewing X of X

NAME    SOURCE HOMEPAGE                         DESCRIPTION VERSIONS UPDATED
xxxxx   dt     http://xxxxx/                                1        2016-XX-XX
xxxyy   dt     http://xxxyy/                                1        2016-XX-XX
......

インストール

検索結果の”SOURCE"に注意する。
SOURCEがdtならdt~<名前>が指定するべき名称。

$ typings install dt~XXXXX --save --global

初期化

設定ファイル作成

$ typings init

typings.jsonが作成される

tsconfig.jsonの"files"にtypings/index.d.tsを追加しておく。

{
    "compilerOptions": {
        ...
    },
    "files": [
        ... , 
        "typings/index.d.ts", 
        ... , 
    ]
}

バージョン

この界隈の時の流れは早すぎるので念のため……

$ typings --version
1.3.3
3
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
3
2