requirejs - Typescript AMD Module not returning anything -
i exporting simple function inside of "log.ts" file:
export function message(s : string) { console.log(s); } this imported file ("mycontroller.ts") in same directory:
import log = module("./log"); class mycontroller { : string = "aaa"; constructor () { log.message("hello world"); } } when compiled, following js:
define(["require", "exports", "./log"], function(require, exports, __log__) { var log = __log__; var mycontroller = (function () { function mycontroller() { this.a = "aaa"; log.message("hello world"); } return mycontroller; })(); }) //@ sourcemappingurl=mycontroller.js.map this define function should return mycontroller. because not, callback inside snippet not controller parameter:
require(["mycontroller"], function (controller) { theroute.controller = controller; defer.resolve(); $rootscope.$apply(); }); i can fix manually adding return inside of call define, not workaround because js being outputted ts compiler.
am doing wrong or bug in typescript?
you should write:
import log = module("./log"); export class mycontroller { // <--- 'export' : string = "aaa"; constructor () { log.message("hello world"); } } and:
require(["mycontroller"], function (controller) { theroute.controller = new controller.mycontroller(); // <-- defer.resolve(); $rootscope.$apply(); }); starting in 0.9.x you'll able write export = mycontroller; @ bottom of .ts file make class top-level exported object.
Comments
Post a Comment