why assignable between "void" and "unknown" in function's return type?

Viewed 51

i think i had meet a paradox in typescript: Playground Link

/* A1 */ declare let a: void;
/* A2 */ declare let b: unknown;
/* A3 */ a = b; // error thrown here
/* A4 */ b = a; // no error

/* L1 */ let f1 = (): void => { return; }
/* L2 */ let f2 = (): unknown => { return; }
/* L3 */ f1 = f2; // no error
/* L4 */ f2 = f1; // no error

actually the range of void is actually more narrowly than unknown, A3 will throw an error.

then, with type theory of Covariance & Contravariance, we can preduce that one of L3/L4 should also throw an error, but it doesn't.

why ?

0 Answers
Related