HaxeFoundation/haxe — pull request #2185 by deltaluca (2013-09-18 23:17:53+00:00)
Title: Permit json syntax more generally for anon-types.

var obj:{"var":Bool} = {"var":true};
trace(obj."var");

i understand @Simn has said there was 'some' reason this sort of thing hasn't been added before, and whether the exact syntax would be wanted or not is to be decided.

However, even if we reject the obj."var" syntax (Although this is 'so' much better than Reflect use, especcialy since the lifting of the type restriction means such usage is staticly checked now), having the non-haxe-ident fields as part of the type is surely better than allowing things like:

var obj = {x:10};
obj = {x:10, "other_field": 20, "hahah you suck": 30 };

going through compile because the non-haxe idents are just 'not checked'.

The main usage for this sort of thing, like with json syntax itself is for working with js target, in my specific case, providing typed externs for a lib which uses non-haxe idents for object fields, and without this there's just no way to type it nicely without changing the field name and providing a horrible wrapper to then assign the real field using untyped __js__... ew.