Am 05.11.2014 um 18:08 schrieb Juraj
Kirchheim:
This is interesting. When string fields in
anonymous objects where first defined, they were ignored by the
typer, as also suggested by the manual:
http://haxe.org/manual/types-structure-json.html
So I would call that a bug and suggest filing an issue.
I reported this as a bug. But there are some other oddities which I
am unsure if they are bugs or intended:
typedef Record = {
recid: Int,
}
class Test {
static function getRecord(r: Record) {
trace(r.recid);
}
static public function main() {
var r = { recid: 12, "x-foo": "Hi" };
getRecord(r); // works
r = { recid: 12, "x-foo": "Hi" }; // throws
{ recid : Int } has extra field x-foo
var r2 = { recid:13, "foo": "Hi"}; // throws
{ recid : Int, foo : String } should be Record
getRecord(r2);
}
}
it's not very intuitive I would say ...
If the last one works, this would be an ideal solution (quote the
fields) for the situation where you have to pass a structure with
more unknown fields like in:
var records: Array<Record> = [
{ recid: 1, "fieldName": "Obama", "fieldAddress": "White
House"},
{ recid: 2, "fieldName": "Putin", "fieldAddress": "Kreml"},
];