Closed
Description
Version. 3.7-beta
Code
export interface CalcObj<O> {
read: (origin: O) => CalcValue<O>;
}
export type CalcValue<O> = CalcObj<O>;
function foo<O>() {
const unk: CalcObj<unknown> = { read: (origin: unknown) => unk }
const x: CalcObj<O> = unk;
}
Expected behavior:
No error on the assignment to x
.
Actual behavior:
Error. unknown
is not assignable to O
. The parameter O
is being measured as invariant.
This works correctly on 3.6.3 and below. The usual tricks to avoid variance-based comparisons let the assignment pass.
Also, removing the type alias works too:
export interface CalcObj<O> {
read: (origin: O) => CalcObj<O>;
}
function foo<O>() {
const unk: CalcObj<unknown> = { read: (origin: unknown) => unk }
const x: CalcObj<O> = unk; // fine!
}
Probably caused by #33050.
Playground Link: link