typescript - Different behaviour of "export = class" -
i writing external module (using amd) needs export single class. want import import myclass = require('./myclass')
, therefore in myclass module use "export =" syntax:
export = class myclass { // ... }
this compiles without errors , produces reasonable js code:
define(["require", "exports"], function (require, exports) { return (function () { function myclass() { /* ... */ } return myclass; })(); });
next, try import it:
import myclass = require('./myclass'); var my: myclass = new myclass();
compiling gives me error @ "var my: myclass": "ts2304: cannot find name 'myclass'".
but, when change module export to:
class myclass { // ... } export = myclass;
everything works okay, produced js code seems same:
define(["require", "exports"], function (require, exports) { var myclass = (function () { function myclass() { /* ... */ } return myclass; })(); return myclass; });
as far can see, difference is, uses temporary variable before return, has no effect outside of closure.
so what's difference , why ts2304 error in first case? should not both cases work same?
should not both cases work same?
they should. please report error here : https://github.com/microsoft/typescript/issues
Comments
Post a Comment