Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

typedef with @:native metadata #48

Open
clarkjones opened this issue Aug 23, 2020 · 4 comments
Open

typedef with @:native metadata #48

clarkjones opened this issue Aug 23, 2020 · 4 comments

Comments

@clarkjones
Copy link

when running dts2hx on puppeteer it generates a Request typedef that contains the following.

@:native('continue')
function continue_(?overrides:Overrides):js.lib.Promise<Void>;

From what I can tell this only works for classes & interfaces

@haxiomic
Copy link
Owner

haxiomic commented Aug 24, 2020

Hey @clarkjones, you’re right and unfortunately haxe does not have a way to solve this yet! There is a proposal to support @:native on typedef fields so this may work in the near future

More discussion on the haxe repo:
HaxeFoundation/haxe#5105

@clarkjones
Copy link
Author

thanks for the info.
Creating an extern interface is not an option in dts2hx?

@haxiomic
Copy link
Owner

haxiomic commented Aug 24, 2020

In this case an interface might do but not in the general case because we need the structure unification rules to apply, so a typedef gives you the most typescript-like behavior here

@haxiomic
Copy link
Owner

haxiomic commented Nov 21, 2020

Just a note for future self, I think we can solve this by wrapping the typedefs with abstracts – not perfect but it will help as an interim before future compile changes fully resolve the issue

typedef StructureTypedef = {
    @:native('continue')
    function continue_(?overrides:Overrides):js.lib.Promise<Void>;
}

abstract Structure(StructureTypedef) {
    @:from static function fromTypedef(obj: StructureTypedef) {
        // apply @:native fields
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants