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

Using a Typescript .d.ts file that doesn't declare a module

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

import * as THREE from "three"

Visual Studio智能感知很高兴。但是,这不适用于 Detector.js (a three.js library for detecting webgl support), with this .d.ts 文件。我不确定是什么问题,但我确实注意到 three.d.ts 文件导出 一个模块(三个)和检测器。d.ts 文件仅导出一个对象:

三个.d.ts

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

探测器.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;

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

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

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

declare module "path/to/detector" {
    export = DetectorStatic;
}