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