How to define extern node module's subpackages?

Simplified, I have the following node js module, that I want to define in extern somehow.

In the JS module there is a property on itself that’s content is also a require of another module that contains multiple classes.

So my main module require another module, and I can access that module through that property in JS. But how can I define such think with externs. I reached something, but it’s really not what I want:

extern class MainModule  {
  var util:Util
}

extern typedef Util {
  var ApplicationError:Class<ApplicationError>;
}

extern class ApplicationError {
  function new(msg:String);
}

use jsRequire like this:

@:jsRequire("MainModule  ", "ApplicationError") // ApplicationError is the property name
extern class ApplicationError {
  function new(msg:String);
}

it will output something like:

var js_MainModule  _propertyName = require("MainModule").ApplicationError;

More info here

1 Like