Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to access "exports" object in TypeScript modules?

I am trying to use durandal and I need to getModuleId by passing the current module. My problem is that as I am using TypeScript, the underlaying object which is returned from AMD module seems not to be accessible by Typescript code:

export function checkModule(){
       var a = system.getModuleId(??);
}

the compiled TS will be converted into this:

function checkModule(){
     var a = system.getModule(??);
}
exports.checkModule = checkModule;

instead of ?? I need to pass exports object which is defined in compiled TS. Is there anyway to do that or there is a much simple way? thanks

like image 492
Bakhshi Avatar asked May 15 '13 01:05

Bakhshi


People also ask

Does module exports work in TypeScript?

TypeScript supports export = to model the traditional CommonJS and AMD workflow. The export = syntax specifies a single object that is exported from the module. This can be a class, interface, namespace, function, or enum.

Can you import module exports?

The export declaration is used to export values from a JavaScript module. Exported values can then be imported into other programs with the import declaration or dynamic import.

How do you call a export function in TypeScript?

Use named exports to export a function in TypeScript, e.g. export function sum() {} . The exported function can be imported by using a named import as import {sum} from './another-file' . You can use as many named exports as necessary in a single file.

Are module exports objects?

module. Exports is the object that is returned to the require() call. By module. exports, we can export functions, objects, and their references from one file and can use them in other files by importing them by require() method.


1 Answers

The following is what I use. You are saying "There is an exports variable out there" ... and well there is :)

declare var exports; 
var thisModule = exports; 
like image 160
basarat Avatar answered Sep 20 '22 11:09

basarat