你如何使用作为模块的 TypeScript 类型?

How do you use TypeScript typings that are modules?

我正在尝试使用 typings to load a definition file for bowser. I've got typings installed and run typings install dt~bowser -DG --save-dev to install it locally. This works great. However now I'm at a loss as to how to use it. In the past, it has "just worked" - meaning, now if I try and write something that references bowser in TypeScript, it will find my definition file (downloaded with typings from DefinitelyTyped) 并将 bowser 识别为全局函数。但是现在,看起来定义文件已经更改,现在是 "module":

declare module 'bowser' {
   var def: BowserModule.IBowser;
   export = def;
}

我应该如何在我的 TypeScript 文件中使用它?我当然可以这样做:

declare var bowser: BowserModule.IBowser;

但那种感觉wrong/hacky。我在这里错过了什么——typings/DefinitelyTyped 的世界发生了什么变化?

The correct syntax would be

import bowser = require('bowser') 

如果您的输入配置正确,它应该可以工作。否则,请检查您的构建脚本中是否引用了 typings/index.d.ts 文件,以及是否在其中正确引用了 bowser:

/// <reference path="globals/bowser/index.d.ts" />