1

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?

Trygve
  • 591
  • 1
  • 7
  • 22
  • Your question is very unclear. please provide a specific scenario and as many details as you can. code would also be good. – gilamran Aug 27 '15 at 19:52

1 Answers1

2

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;
}
David Driscoll
  • 1,399
  • 11
  • 13
  • Ok. Thanks! That makes sense. Though, why doesn't the Definitely Typed file include this? Is there a different way to use `.d.ts` files that doesn't require the use of a module? – Trygve Aug 28 '15 at 00:30
  • In my case, I'm not sure this answer is actually correct, but it was darned close. I've added a little detail to my question. What I found to work was: In the adhoc `custom.d.ts` file put `declare module "Detector" { export = DetectorStatic; }` In my tsd.d.ts file add a line: `/// `. To import the file, use `import Detector = require("Detector");` instead of `import {Detector} from "Detector";` (Details on this last part [here](https://github.com/Microsoft/TypeScript/issues/2242)). – Trygve Aug 28 '15 at 03:10