Closed as not planned
Description
🔎 Search Terms
covariance
contravariance
🕗 Version & Regression Information
(Please suggest a better title 😅)
Recently Andrew Burgess posted a video related to covariance and contravariance, and also the in
and out
keywords
Noticed issue related to assignability while playing around with the code
- This is the behavior in every version I tried
⏯ Playground Link
💻 Code
type Job = {
enqueuedAt: Date;
transactionId: string;
name: string;
};
type PriorityJob = Job & {
priority: true;
level: 1 | 2 | 3;
};
type Queue<J> = {
enqueue: (j: J) => void;
getJob: (id: string) => J;
// enqueue(j: J): void;
// getJob(id: string): J;
};
declare const jobQueue: Queue<Job>;
declare const priorityJobQueue: Queue<PriorityJob>;
const q3: Queue<Job> = jobQueue;
const q4: Queue<Job> = priorityJobQueue;
const q5: Queue<PriorityJob> = jobQueue;
const q6: Queue<PriorityJob> = priorityJobQueue;
🙁 Actual behavior
If the methods defined in the Queue
type (without using in
and out
keywords) used the arrow function syntax, there are two of the four assignments which are errors.
But if using the normal function syntax, only one is erroring.
🙂 Expected behavior
Consistent behaviour is expected in all cases.
Additional information about the issue
No response