使用没有声明模块的Typescript .d.ts文件

时间:2015-08-27 18:11:04

标签: three.js typescript definitelytyped tsd

我使用tsd从Definitely Typed下载定义并编译成tsd.d.ts文件。我还没有能够构建,但是当我使用这样的导入时:

import * as THREE from "three"

Visual Studio intellisense很高兴。但是,这对Detector.js(用于检测webgl支持的three.js库)以及this .d.ts文件不起作用。我不确定是什么问题,但我确实注意到三个.ts文件导出 模块(THREE)和detector.d.ts文件只导出一个对象:

three.d.ts

...
declare module 'three' {
    export=THREE;
}

detector.d.ts

interface DetectorStatic {
    canvas: boolean;
    webgl: boolean;
    workers: boolean;
    fileapi: boolean;

    getWebGLErrorMessage(): HTMLElement;
    addGetWebGLMessage(parameters?: {id?: string; parent?: HTMLElement}): void;
}

declare var Detector: DetectorStatic;

这会改变我导入探测器的方式吗?

1 个答案:

答案 0 :(得分:2)

对于这样的情况,您可以定义自己的。对于大多数项目,我通常都有一个adhoc .d.ts文件,我会抛出我需要的随机声明(小接口,模块,等等)。

您应该能够在代码中的某个位置简单地定义模块。

declare module "path/to/detector" {
    export = DetectorStatic;
}
相关问题