Hacker News new | past | comments | ask | show | jobs | submit login

What's wrong with Object?



If I set input as Object,

    if (input[prefCode] !== null) {
        currentValue = input[prefCode].toString();
    }
in the lines above, I see a red underline under input[prefCode]

> Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'Object'. No index signature with a parameter of type 'string' was found on type 'Object'.ts(7053)


Could you use a helper like

    function getProperty<T, K extends keyof T>(o: T, propertyName: K): T[K] {
        return o[propertyName];
    }

?




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: