I have been attempting to update a project from TypeScript 2.3 to 2.4, but the process has become quite frustrating and perplexing. I am encountering errors related to generics that are proving difficult to comprehend.
To simplify the issue, I have extracted a portion of the code:
interface Service {
serviceName: string;
}
interface TableParams {
selectionListLabelFn: <T>(item: T) => string;
}
const tableParameters: TableParams = {
selectionListLabelFn: (service: Service) => service.serviceName
};
The snippet above results in the following error:
λ tsc test.ts
test.ts(9,7): error TS2322: Type '{ selectionListLabelFn: (service: Service) => string; }' is not assignable to type 'TableParams'.
Types of property 'selectionListLabelFn' are incompatible.
Type '(service: Service) => string' is not assignable to type '<T>(item: T) => string'.
Types of parameters 'service' and 'item' are incompatible.
Type 'T' is not assignable to type 'Service'.
What could be causing this issue? I find it completely nonsensical.