Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

In my javascript file I have:

require(["menu/main-menu"], function (mainMenu) {

where main-menu is built from main-menu.ts. javascript/requireJS wants me to build up a define I return in main-menu. But typescript doesn't do that AFAIK.

How can I accomplish this?

Update: For example, the following tells me the export keyword is incorrect:

///<reference path='../../libs/ExtJS-4.2.0.d.ts' />
///<reference path='../../libs/require.d.ts' />

import fdm = require("./file-definitions");
require(["../../scripts/ribbon"], function () {

export module Menu {

    export class MainMenu {
    }
}
share|improve this question

2 Answers

To do a manual require (e.g. for a lazy load) with a callback you can use the RequireJS definitions for TypeScript from DefinitelyTyped : https://github.com/borisyankov/DefinitelyTyped/tree/master/requirejs

share|improve this answer
 
How do I set up a manual require? I tried require(...) and can't find a way that works. –  David Thielen 17 hours ago
 
Exactly the same as you would do in javascript –  basarat 13 hours ago
 
I tried that, still doesn't work (see the update above with my specific code listed). Is there anything else? Thanks - dave –  David Thielen 1 hour ago

If I understand your question correctly you want to access MainMenu in JavaScript using RequireJS? Then your JavaScript should look like:

require(["path/to/MainMenu"],function(mainMenu){
    mainMenu.doSomething();
});

Now, assuming you are using TypeScript 0.9.1 or later, you can assign a value to the exported value of your module. So you could write your MainMenu.ts file like this:

class MainMenu {
    doSomething(): void {
    }
}
export = MainMenu;
share|improve this answer
 
I tried that, still doesn't work (see the update with my specific code listed). Is there anything else? Thanks - dave –  David Thielen 1 hour ago
 
I still get an error on the export in "export module Menu". How can I avoid that? thanks - dave –  David Thielen 47 mins ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.