Nicholas Head Nicholas Head - 1 month ago 8x
TypeScript Question

How do you use TypeScript typings that are modules?

I'm trying to use typings to load a definition file for bowser. I've got typings installed and run

typings install dt~bowser -DG --save-dev
to install it locally. This works great. However now I'm at a loss as to how to use it. In the past, it has "just worked" - meaning, now if I try and write something that references bowser in TypeScript, it will find my definition file (downloaded with typings from DefinitelyTyped) and recognize
as a global function. Now however, it looks like the definition file has changed and it's now a "module":

declare module 'bowser' {
var def: BowserModule.IBowser;
export = def;

How am I supposed to use this in my TypeScript files? Of course I can do something like this:

declare var bowser: BowserModule.IBowser;

But that feels wrong/hacky. What am I missing here-- what's changed in the world of typings/DefinitelyTyped?


The correct syntax would be

import bowser = require('bowser') 

If your typings are properly configured, it should work. Else, check if the typings/index.d.ts file is referenced in your build script, and if bowser is properly referenced in there:

/// <reference path="globals/bowser/index.d.ts" />