问题
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