In regard to the function getCards
, how can a type be declared for the input of memoize
? The input is a reference to a function.
import memoize from "fast-memoize";
function getCards<T>(
filterBy: string,
CardsList: T[] = CardsJSON.map((item, i) => ({ ...item, id: i }))
) {
return CardsList;
}
// My attempted solution.
// const testType: Array<ICard> = getCards<ICard>("test");
const fn = memoize(getCards);
A type error related to CardsList is being encountered. It seems to be difficult to pinpoint the exact cause of the error..?
TS2322: Type '{ id: number; spId?: string | undefined; callToAction?: string | undefined; cardTags?: any[] | undefined; campaignId: string; cardTitle: string; cardDescription: string; endAgeLimit?: number | undefined; ... 37 more...; updatedAt: string; }[]' is not assignable to type 'T[]'. Type '{ id: number; spId?: string | undefined; callToAction?: string | undefined; cardTags?: any[] | undefined; campaignId: string; cardTitle: string; cardDescription: string; endAgeLimit?: number | undefined; ... 37 more ...; updatedAt: string; }' is not assignable to type 'T'.