Typescript AMD implementation bad with Javascript / RequireJS -
if have ts module:
export function say(){ console.log("said"); }
and compile amd option can use quite ts client :
import foo = module("tsmodule") foo.say(); export var x = 123;
however if have javascript equivalent ts module:
define(["require", "exports"], function(require, exports) { function say() { console.log("said"); } exports.say = say; })
there no way use easily. simplest possible solution:
// of course can use .d.ts requirejs beside point declare var require:any; // fail error module has not been loaded yet context // http://requirejs.org/docs/errors.html#notloaded var useme = require("jsmodule") useme.say(); export var x = 123; import foo = module("tsmodule") foo.say();
fails because of error http://requirejs.org/docs/errors.html#notloaded . since "jsmodule" not passed define call in generated typescript.
the 2 workarounds have
- don't use import / export (language features lost)
- use require([]) (still can't export depends on require([]) call)
have limitations : https://github.com/basarat/typescript-requirejs . there way? if not can vote here : https://typescript.codeplex.com/workitem/948 :)
if want load in javascript module use (badly documented) amd-dependency
tag:
/// <amd-dependency path="jsmodule" />
this put jsmodule
in dependency array of define call.
and provide declaration file in state
module useme { function say(): void; }