Experiencing issues with existing TypeScript code breaking due to changes in generic inference.
For instance:
interface Task {
num: number;
}
interface MyTask extends Task {
description: string;
}
interface Job {}
type Executor<J> = <T extends Task>(job: J, task: T) => T;
const myExecutor: Executor<Job> = (job: Job, task: MyTask) => {
if (task.num === 123) {
return;
}
else {
return;
}
};
The error message during compilation reads as follows:
Error:(11, 7) TS2322:Type '(job: Job, task: MyTask) => {}' is not compatible with the type 'Executor<Job>'.
The parameters 'task' and 'task' are conflicting.
Type 'T' cannot be assigned to type 'MyTask'.
Type 'Task' cannot be assigned to type 'MyTask'.
The property 'description' is missing from type 'Task'.