On 12/2/15, 2:37 PM, "Josh Tynjala" <joshtynj...@gmail.com> wrote:
>Oh, I see. I didn't realize that you were thinking that users would import >something and also manually call require(). In that case, yes, you could >still potentially have proper type checking. > >I like the idea of using some kind of wrapper class to hide the require() >call. It's kind of messy to both import and call require(), so I really >would prefer to hide one or the other, if possible. It's up to you or whoever writes this code. A wrapper adds a layer of function calls but does let you hide some ugliness. > >There's one thing that seems like an issue to me, though. Using an as cast >with require() will probably result in a null result because what is >returned by require("fs") doesn't actually extend an FS class (or >implement >an FS interface). > >var fs:FS = require("fs") as FS; We have this problem already. There is a special ASDoc tag called @flexjsignorecoercion that suppresses "as" code in the cross-compiled output. I've considered trying to get the compiler to automatically suppress the "as" code for any "as" usage that references a class in an external-library-path SWC. That seems like it could fail you in some distributed development cases where you have other code that does support AS in an external-library-path SWC. We could add file-level suppression as well, or have a config option that lists certain coercions to always suppress. Definitely open to ideas on this, but the fact is, the compiler will not let you have type-checking without using "as" so you sort of have to have a scheme to deal with it. -Alex