-
Trying to write a binding for Node's
Getting this error:
Any ideas? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Unfortunately, defining a JsType is only part of the process - this only tells j2cl what the type is, and how to accurately generate references to it from other types (plus also how to work out constants, some helper methods, etc). The other part of the puzzle you need is to give the closure compiler the externs for the type. See https://developers.google.com/closure/compiler/docs/externs-and-exports for a quick summary, and https://github.com/google/closure-compiler/tree/master/contrib/externs for some other example files. In your case, add a js file to the project that looks something like this: /**
* @externs
*/
function process() {}
/**
* @returns number[]
*/
process.hrtime = function(){}; I'm not quite sure if this is actually accurate for your purposes, but it seems to reflect the Java you've declared. For example there is a constructor for process, but no members, just a single static function. When naming this file, we are encouraging a Personally I would suggest putting it in the same package as the Process.java file above, so that if you update one, you know to also update the other. |
Beta Was this translation helpful? Give feedback.
Unfortunately, defining a JsType is only part of the process - this only tells j2cl what the type is, and how to accurately generate references to it from other types (plus also how to work out constants, some helper methods, etc).
The other part of the puzzle you need is to give the closure compiler the externs for the type. See https://developers.google.com/closure/compiler/docs/externs-and-exports for a quick summary, and https://github.com/google/closure-compiler/tree/master/contrib/externs for some other example files.
In your case, add a js file to the project that looks something like this: