I'd like to access typed object with bracket notation like this:
interface IFoo {
bar: string[];
}
var obj: IFoo = { bar: ["a", "b"] }
var name = "bar";
obj[name]. // type info lost after dot
According to the spec 4.10 as far as I understood it, it is an 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.
Can anyone confirm if that is true and if it is possible to circumvent this behavior.
Edit: My use case is with object minification as in
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)
}