Typedef which extends a class

161 views
Skip to first unread message

Haxiomic

unread,
Mar 23, 2016, 6:08:56 PM3/23/16
to Haxe
Hey all,

I seem to come across this case often: you want to define a type that's equal to ClassA but also has some extra fields or methods. This is possible with

typedef NewType = {
   
>ClassA,
   
function extraMethod():Void;
}

But since haxe 3.2.0 it's been depreciated and you get a warning "Structurally extending classes is deprecated and will be removed"

Is there an alternative way of doing this or is it a case of deprecated-because-it's-bad-practise?

I gather I can do this by defining my new type as a class that extends ClassA and then creating subsequent types that extend my new type, however this approach lacks flexibility, especially when working with externs or libraries where you don't get to control what extends what

Many thanks,
George

Benjamin Dubois

unread,
Mar 24, 2016, 2:33:22 PM3/24/16
to Haxe

maybe traits can meet your needs ?
http://haxe.org/manual/lf-static-extension.html


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