Skip to content

Instantly share code, notes, and snippets.

@ccapndave
Created June 18, 2012 22:56
Show Gist options
  • Select an option

  • Save ccapndave/2951285 to your computer and use it in GitHub Desktop.

Select an option

Save ccapndave/2951285 to your computer and use it in GitHub Desktop.
class TypeTest {
public static function main() {
myFunc({});
myFunc({ a: "Hello" });
myFunc({ b: 1 });
myFunc({ another: "something" });
}
private static function myFunc(o:Opts):Void { }
}
// If I use this I get an error when using { another: "something" }
typedef Opts = {
@:optional var a:String;
@:optional var b:Int;
};
// If I use this I get '{ } should be Opts'
class Opts implements Dynamic {
var a:String;
var b:Int;
}
// Ideally I want this, but its not allowed ('cannot only extend classes and anonymous')
typedef Opts = {
> Dynamic,
@:optional var a:String;
@:optional var b:Int;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment