How to read Dynamic's property whose name is a Haxe keyword?

55 views
Skip to first unread message

Web Master

unread,
Sep 2, 2017, 6:11:28 PM9/2/17
to Haxe
Hello

How to read Dynamic's property whose name is a Haxe keyword?

For example, .default of a ES6 module

    var dygraphs = Webpack.require('dygraphs'); // : Dynamic
    trace(dygraphs.default);                  // Error: Unexpected default
    trace((untyped dygraphs)['default']);     // Error: String should be Int

Gama11

unread,
Sep 3, 2017, 5:51:43 AM9/3/17
to Haxe
Try Reflect.field(dygraphs, "default").

Philippe Elsass

unread,
Sep 3, 2017, 9:29:57 AM9/3/17
to Haxe
If it's a class you should use @:jsRequire for that:

@:jsrequire('dygraph', 'default')
extern class Dygraph {...}

If it's an object:

var dygraphs:DynamicAccess = Webpack.require('dygraphs');
trace(dygraph.get('default'));

PS: looks like something to fix in the Webpack class as well, please raise an issue about that.

Cheers, 
Philippe


--
To post to this group haxe...@googlegroups.com
http://groups.google.com/group/haxelang?hl=en
---
You received this message because you are subscribed to the Google Groups "Haxe" group.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages