你如何使用作为模块的 TypeScript 类型? [英] How do you use TypeScript typings that are modules?
问题描述
我正在尝试使用 typings 来加载 bowser.我已经安装了 Typings 并运行 typings install dt~bowser -DG --save-dev
在本地安装它.这很好用.但是现在我不知道如何使用它.过去,它刚刚工作"——意思是,现在如果我尝试在 TypeScript 中写一些引用 bowser 的东西,它会找到我的定义文件(从 DefinitelyTyped) 并将 bowser
识别为全局函数.然而,现在看起来定义文件已经改变,它现在是一个模块":
I'm trying to use 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) and recognize bowser
as a global function. Now however, it looks like the definition file has changed and it's now a "module":
declare module 'bowser' {
var def: BowserModule.IBowser;
export = def;
}
我应该如何在我的 TypeScript 文件中使用它?我当然可以这样做:
How am I supposed to use this in my TypeScript files? Of course I can do something like this:
declare var bowser: BowserModule.IBowser;
但这感觉不对.我在这里缺少什么 - 打字/DefinitelyTyped 的世界发生了什么变化?
But that feels wrong/hacky. What am I missing here-- what's changed in the world of typings/DefinitelyTyped?
推荐答案
import bowser = require('bowser')
如果您的打字配置正确,它应该可以工作.否则,请检查您的构建脚本中是否引用了 typings/index.d.ts
文件,以及其中是否正确引用了 bowser:
If your typings are properly configured, it should work. Else, check if the typings/index.d.ts
file is referenced in your build script, and if bowser is properly referenced in there:
/// <reference path="globals/bowser/index.d.ts" />
这篇关于你如何使用作为模块的 TypeScript 类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!