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

戏子无情 提交于 2019-12-13 18:11:22

问题


I'm using tsd to download definitions from Definitely Typed and compile into a tsd.d.ts file. I haven't been able to build yet, but when I use an import like this:

import * as THREE from "three"

Visual Studio intellisense is happy. However, this doesn't work for Detector.js (a three.js library for detecting webgl support), with this .d.ts file. I'm not sure what the issue is, but I did notice that the three.d.ts file exports a module (THREE) and detector.d.ts file just exports an object:

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;

Does that change how I should be importing Detector?


回答1:


For a case like this, you can define your own. For most projects I usually have an adhoc .d.ts file that I throw random declarations that I need (small interfaces, modules, whatever).

You should be able to simply define the module somewhere in your code.

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


来源:https://stackoverflow.com/questions/32256612/using-a-typescript-d-ts-file-that-doesnt-declare-a-module

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!