I have been attempting to utilize _.find in TypeScript on an Object in order to retrieve a value from this object. The original code snippet looked like this:
const iconDict = {
dashboard: <DataVisualizer />,
settings: <SettingsApp />,
'company-manager': <CompanyManager />,
'tenant-administrator': <TenantAdministrator />,
glob
const icon =
_.find(iconDict, (icon, key) => {
const url = window.location.href
if (url.indexOf(key) !== -1) {
return icon
}
}) || iconDict['global']
The code above is resulting in an error:
const icon =
_.find<typeof iconDict, JSX.Element>(iconDict, (icon, key) => {
const url = window.location.href
if (url.indexOf(key) !== -1) {
return icon
}
Which then resulted in:
Argument of type '(icon: Element, key: string) => Element | undefined' is not assignable to parameter of type 'ObjectIteratorTypeGuard'. Signature '(icon: Element, key: string): Element | undefined' must be a type predicate.ts(2345)
As it falls under this specific definition
At this point, I am uncertain of how to proceed. How can I ensure that TypeScript understands I will return either a type from the object's value or undefined?
Thank you