I know I can't use a string
as a object index because it's too unspecific and for that I should use keyof
but I wondering why can't I use a string
even after check it is a valid index with the in
operator.
Example:
if (fieldName in someObject) {
const fieldValue = someObject[fieldName];
}
Typescript complain about this. I understand it can't compute the fieldValue
type, but give an any
type would be good enough.