dts2hx icon indicating copy to clipboard operation
dts2hx copied to clipboard

typedef with @:native metadata

Open clarkjones opened this issue 5 years ago • 4 comments

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

clarkjones avatar Aug 23 '20 14:08 clarkjones

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: https://github.com/HaxeFoundation/haxe/issues/5105

haxiomic avatar Aug 24 '20 05:08 haxiomic

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

clarkjones avatar Aug 24 '20 12:08 clarkjones

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 avatar Aug 24 '20 19:08 haxiomic

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
    }
}

haxiomic avatar Nov 21 '20 23:11 haxiomic