I am currently in the process of creating a function that can take in an object with a specific data type, as well as a function that acts on that data type as its argument.
const analyze = <
Info extends object,
F extends {initialize: Info; display: (info: Info) => any}
>(
component: F
) => {}
However, when I attempt to utilize this function, TypeScript only recognizes the general object
data type that is extended by the Info
, rather than the actual structure of the data within the property:
analyze({
initialize: {name: 'Alice'},
display: (information) => {
// Error: Property 'name' does not exist on type 'object'
return information.name
}
})
How can I define Info
so that TypeScript accurately infers its structure?