LoginSignup
4
4

More than 5 years have passed since last update.

TypeScriptのビルド設定をES5からES6に変えた時にエラーが発生した時の解決

Last updated at Posted at 2015-12-21

Node.jsで使用していたTypeScriptのプロジェクトをES5からES6に変えたら見慣れぬエラーが発生した。

index.ts
/// <reference path="typings/es6-promise/es6-promise.d.ts" />
"use strict";

new Promise((resolve: Function) => {

    setTimeout(() => {
        console.log("3秒経ったよ!");
        resolve();
    }, 3);
});
tsconfig.json
{
    "compilerOptions": {
        "module": "commonjs",
        "noImplicitAny": true,
        "removeComments": false,
        "preserveConstEnums": true,
        "out": "index.js",
        "sourceMap": false,
        "target": "es6"
    },
    "files": [
        "index.ts"
    ]
}
console.sh
$ tsc -p . 

/Users/username/.nodebrew/node/v5.1.0/lib/node_modules/typescript/lib/lib.es6.d.ts(5074,11): error TS2300: Duplicate identifier 'Promise'.
/Users/username/.nodebrew/node/v5.1.0/lib/node_modules/typescript/lib/lib.es6.d.ts(5155,13): error TS2300: Duplicate identifier 'Promise'.
typings/es6-promise/es6-promise.d.ts(11,15): error TS2300: Duplicate identifier 'Promise'.
typings/es6-promise/es6-promise.d.ts(42,16): error TS2300: Duplicate identifier 'Promise'.

もともとNode.jsのPromiseを使うために、https://github.com/DefinitelyTyped/DefinitelyTypedes6-promiseを使用していたのだけれども、PromiseはES6から標準になるため、d.tsファイルがあると重複して定義が存在することになってしまうようだ。
そのためes6-promise.d.tsファイルへのリファレンスを消してしまえば、上記のエラーは発生しなくなった。

以上。

4
4
1

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
4