CanAssign<number | string, number> // boolean
We are checking can A
assign to B
.
Since A
is number | string
,
A
can assign to B
when A
is number(true), and
Acannot assign to
Bwhen
A is string
(false).
So the result is true | false = boolean
.
If you want to make sure all branches are assignable,
use StrictCanAssign<A, B>
.
Can
A
assign toB
Note that when union is involved, the assignability is measured distributively. Meaning the result can be
Then | Else
(i.e.boolean
by default), instead of distinctiveThen
(true
) orElse
(false
).This is the correct behavior.