Created
May 2, 2019 08:20
-
-
Save kLabz/46cd0d227bd3c0e2da207f9c05e50f4a to your computer and use it in GitHub Desktop.
Extends<T>
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Test { | |
static function main() { | |
var a:Extends<A> = extended({a: "hello", b: "world"}); | |
$type(a); // Extends<A> | |
trace(haxe.Json.stringify(a)); | |
a.a = "bye"; | |
// a.a = 42; // Int should be String | |
// a.b = "nope"; // Extends<A> has no field b | |
trace(haxe.Json.stringify(a)); | |
// -------- | |
var props:WrapperProps = { | |
whatever: true, | |
AProps: extended({a: "hello", b: "world"}) | |
}; | |
trace(haxe.Json.stringify(props)); | |
} | |
static function extended<Base, T:Base>(obj:T):Extends<Base> | |
return cast (obj :Extended<Base, T>); | |
} | |
typedef A = { | |
var a:String; | |
} | |
typedef WrapperProps = { | |
var whatever:Bool; | |
var AProps:Extends<A>; | |
} | |
typedef Extends<T> = T; | |
typedef Extended<T, TExtended:T> = TExtended; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment