I have a company object, that looks like this:
{
tracking_hours: {
open: '8:00',
close: '20:00'
}
}
I use it to set values this way:
set({
openTime: setTime(company, 'open_time'),
closeTime: setTime(company, 'close_time'),
})
I need somehow set a type for company in setTime function
export function setTime(
company: {
tracking_hours: null | any
},
type: string,
): number | null {
if (company.tracking_hours) {
if (company.tracking_hours[type]) {
const time = Number(company.tracking_hours[type].split(':')[0])
if (time) {
return time
} else {
return null
}
}
return null
}
return null
}
How can I replace any with its actual type?
tracking_hours: null | { open: string, close: string }?TS7053: Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{ open: string; close: string; }'. No index signature with a parameter of type 'string' was found on type '{ open: string; close: string; }'.tracking_hoursor restrict the values oftypeto be the kets oftracking_hours? Or something else? Note that right now you're passing in"open_hours"fortypebut the key found on the object isopen.