Closed RamiroWincor closed 4 years ago
I kept thinking on this issue and there is no import as there is no need for it, only the type reference is needed for TSC. I have no previous experiencie with TS but after looking around what it is missing is the "/// <reference path=" for the type definition. I asume that as we are not using the class anywhere (just objects of that class, not as if we were creating new objects) the generated TSC does not add the import wich is nice but also it is not creating the reference when it should.
Hello, thanks for reporting
I assume Wampy is accessible globally.
You should be packaging Wampy JSweet definition as a JSweet candy: https://github.com/cincheo/jsweet/blob/master/doc/jsweet-language-specifications.md#packaging-a-jsweet-jar-candy It is the best way to create a bridge to a JS / TS API. And then, you add it as a maven dependency in your project. This should solve your problems. Also, I recommend that you use package-info.java in def.wampy and wampyJSI
@jsweet.lang.Root()
package def.wampy;
Please close issue if your problem get solved
Hi, It is not globally accesible but it is ony a type dependency. You can check the code but it is something like this:
public class A {
private B client;
public void c (B param) {
param.test();
}
}
B is used in TS but not in JS as all B references are just for typing, so no import is needed. I moved the bridge (that was in the project) to an external candy but I see no diference even including or not the Root package-info.java annotations.
Just for reference here is my bridge:
package def.wampy;
import java.util.function.Consumer;
import def.js.Promise;
@jsweet.lang.Interface
public abstract class Wampy extends def.js.Object {
public native Promise<Object> call(String topicURI, def.js.Array<Object> payload);
public native Promise<Object> call(String topicURI);
public native Wampy subscribe(String paramString, Consumer<java.lang.Object> paramConsumer);
}
And this is one of the classes that use it:
package wampyJSI;
import def.js.Promise;
import def.wampy.Wampy;
import java.lang.Object;
import java.lang.String;
public class JamServiceBeeperPuma {
String name;
Wampy client;
public Promise<Object> run() {
return client.call(name + ".run");
}
public void configureClient(Wampy client, String name) {
this.client = client;
this.name = name;
}
}
Yes, I understand that it is only to create type definitions byt I was talking about the Wampy library itself. It shouldn't be imported as a module, it's used as a global scope variable, right? Do you need to import Wampy module or is it just a lib you access with a global reference, that's the question. According to this it seems that it's a global lib.
Either ways, you have to put your definitions in a candy, packaged in the way described at link I sent you.
You have plenty of examples here: https://github.com/jsweet-candies
Please tell me if you have everything you need.
I have a custom module that I am using in my code, so I made a API bridge for it. My code import the bridge and use it in the code and the generated TS matches with that, but the generated TS is not including the import to the bridge module, so TSC just generate errors like "ERROR output:55 - cannot find name" it does still generate the final JS wich I did not expect.
Creating a bundle works as expected as all TS is bundled so no import is needed for JS generation.
I am using the lastest maven plugin (but tested with previous ones with the same results) and after searching for whatever I could be doing wrong I think I am doing everything as expected. I have attached my project so you can try it (you will need to remove the parent from the pom, everything else should be fine). pumaWampy.zip
Maven traces: