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

Module-level field support or improve class based workaround #89

Open
haxiomic opened this issue Apr 27, 2021 · 0 comments
Open

Module-level field support or improve class based workaround #89

haxiomic opened this issue Apr 27, 2021 · 0 comments

Comments

@haxiomic
Copy link
Owner

haxiomic commented Apr 27, 2021

In TypeScript we have module-level fields like:

declare const cheerio: cheerio.CheerioAPI;
export = cheerio;

Ideally we can represent this in haxe as:

 @:jsRequire("cheerio") extern final cheerio: cheerio.CheerioAPI;

But @:jsRequire() doesn't yet work for module-level-fields

A work around is to convert this to a class that just contains a value:

@:jsRequire("cheerio") extern class Cheerio {
	static var value(get, never) : cheerio.CheerioAPI;
	static inline function get_value():cheerio.CheerioAPI return cast Cheerio;
}

This works but is clunky, it would be better to instead promote the fields of the variable into static fields of this class, for example, cheerio has a function, load():

@:jsRequire("cheerio") extern class Cheerio {
	static extern inline function load(arg) value.load(arg);

	static var value(get, never) : cheerio.CheerioAPI;
	static inline function get_value():cheerio.CheerioAPI return cast Cheerio;
}

However, to support overloads, we require the overload keyword which is only available in haxe 4.2+

It may make sense to spend effort getting module-level extern fields to work in haxe rather than improve this workaround

@haxiomic haxiomic changed the title Add member fields as statics for module-variable-classes Module-level field support or improve class based workaround Apr 27, 2021
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

1 participant