我是打字稿的新手并尝试启动hapi.js项目,但在我的代码中尝试require(' boom')时出现错误
Duplicate identifier 'Boom'
/// <reference path="../typings/tsd.d.ts" />
var config = require('../config'),
User = require('../models/user'),
Boom = require('boom'),
joi = require('joi');
我的tsd.json
{
"version": "v4",
"repo": "borisyankov/DefinitelyTyped",
"ref": "master",
"path": "typings",
"bundle": "typings/tsd.d.ts",
"installed": {
"node/node.d.ts": {
"commit": "846a250e0a6f5e6adf6347ee4ca442a9d1abd8fc"
},
"hapi/hapi.d.ts": {
"commit": "846a250e0a6f5e6adf6347ee4ca442a9d1abd8fc"
},
"bluebird/bluebird.d.ts": {
"commit": "846a250e0a6f5e6adf6347ee4ca442a9d1abd8fc"
},
"boom/boom.d.ts": {
"commit": "846a250e0a6f5e6adf6347ee4ca442a9d1abd8fc"
},
"pg/pg.d.ts": {
"commit": "846a250e0a6f5e6adf6347ee4ca442a9d1abd8fc"
}
}
我已经为我的tsd添加了繁荣和hapi - 如果hapi引用繁荣也会导致某种循环错误?
我应该如何在打字稿中引用这些库?
答案 0 :(得分:2)
If you don't put a global section .text
or import
in your file then as far as TypeScript is concerned you file is a part of a global namespace and therefore you are getting a name collision on export
. Fix: use Boom
instead of import/require
.
var/require
To learn more : https://www.youtube.com/watch?v=KDrWLMUY0R0&hd=1