I would like to access the typed object using brackets:
interface IFoo {
bar: string[];
}
var obj: IFoo = { bar: ["a", "b"] }
var name = "bar";
obj[name].
According to specification 4.10, as I understand it, this is 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.
Can anyone confirm if this is the case and is it possible to circumvent this behavior?
Edit:
My use case with minimizing objects 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)
}
source
share