I am currently working on creating a function that can adapt to any informer and mapper, utilizing dependency injection to ensure the logic remains unchanged even if these components are altered. However, I seem to be encountering difficulties in generalizing my function arguments effectively.
Furthermore, when attempting to modify 'unknown' to 'any' in the signature of myFunc inform, it raises an error indicating that 'any' is not recommended and unexpected.
Interfaces
interface Document {
name: string
}
interface Mapper {
(doc: Document): unknown
}
Function
const myFunc = async (
inform: (payload: unknown)=>Promise<Record<string, unknown>>,
document: Document,
mapper: Mapper): Promise<string> => {
const response = <Record<string, unknown>> await inform(mapper(document));
return response
})
Problem
class APIClient {
async inform(payload: RequestInfo): Promise<Record<string, unknown>> {
// Implementation
}
}
const apiClient = new APIClient();
const result = await myFunc(
apiClient.inform, //Issue arises as it complains about assigning unknown to RequestInfo..
someData,
someMapper
);