I am encountering an issue where I want each record in the object to have different value types, but I keep running into these errors:
1 - 'TSearchInput' could potentially be instantiated with a type that is not related to 'RotatingItemSearchInput'
2 - 'K' could potentially be instantiated with a type that is not related to 'number'
To illustrate the problem, I have created this basic demo:
class RotatingItemSearchInput {}
class OtherItemSearchInput {}
const rotatingItemService = (input: RotatingItemSearchInput) =>
new Promise((res: (val: number) => void) => res(1));
const otherItemService = (input: OtherItemSearchInput) =>
new Promise((res: (val: string) => void) => res('result'));
const filtersMap: Record<
string,
<TSearchInput, K>() => {
searchInput: TSearchInput;
search: (searchInput: TSearchInput) => Promise<K>;
}
> = {
rotatingItem: () => ({
searchInput: new RotatingItemSearchInput(),
search: (searchInput) => rotatingItemService(searchInput),
}),
otherItem: () => ({
searchInput: new OtherItemSearchInput(),
search: (searchInput) => otherItemService(searchInput),
}),
};
I would greatly appreciate your assistance in resolving this issue.