I wish to retrieve a typed object using bracket notation like this:
interface IFoo {
bar: string[];
}
var obj: IFoo = { bar: ["a", "b"] }
var name = "bar";
obj[name]. // type information lost after dot
As per the specification 4.10, it seems to be the expected behavior:
A bracket notation property access of the form ObjExpr [ IndexExpr ]
....
Otherwise, if IndexExpr is of type Any, the String or Number primitive type, or an enum type, the property access is of type Any.
Could someone confirm if this is accurate and suggest any workarounds.
Edit: My situation involves object minification as shown below:
var props = {long_name: "n"};
var shortName = props.long_name;
function(minObj) {
var value = minObj[shortName]
var newMinObj = {};
newMinObj[shortName] = value.toUpperCase();
db.save(newMinObj)
}