cillierscharl
cillierscharl

Reputation: 7117

TypeScript definition file : Exporting an instantiated class

There is a specific typescript definition that I cannot currently get working:

mapping.ts
class Mapping {
//
}
var mapping = new Mapping();
export = mapping;

Which enables the use:

import _mapping = require('mapping');
_mapping.doSomething();

However I cannot quite get to the solution of how my mapping.d.ts should be structured to show this and cannot get it to compile.

mapping.d.ts
export var mapping: Mapping;

This fails since the usage would now be:

 _mapping.mapping.doSomething();

Any suggestions would be appreciated besides updating the usage to include the object name.

Upvotes: 0

Views: 90

Answers (1)

Paleo
Paleo

Reputation: 23682

You can use the syntax export = in the definitions file:

// mapping.d.ts
let mapping: Mapping;
export = mapping;

Upvotes: 1

Related Questions