I am trying to type this function in TypeScript and hitting a dead end every time. It’s complaining about using any as a type of the passed in d object.
const current = (d: any): number => d.currentYear;
Basically, it is a function that takes in an object d and returns .curentYear property value out of it. The shape of the d object may change and hence it can be any object. I tried to look into Generic Types and this is the closest I could find:
const getProperty = <T, K extends keyof T>(obj: T, key: K) => obj[key];
The downside is that I have to pass in the property during the function call:
getProperty(d, 'currentYear')
Is there any better way to type this function signature?