Open webstrand opened 5 years ago
This is an issue with variance markers and conditional types I think. The issue is that when assigning foo
to bar
the checker is just relating the type arguments (string
and any
) which are related. The markers are missing the fact that the type arguments appear as check types in a conditional type.
cc @weswigham
Related: #31251
This is not directly relevant to the issue but in case you want to be able to distinguish any
from never
you can use the following instead:
type IfAny<T, Y, N> = 0 extends (1 & T) ? Y : N;
type Decider<F> = {
prop: IfAny<F, "isAny", "isNotAny">
};
Which, again, doesn't address the actual assignability problem you're talking about.
TypeScript Version: 3.5.0-dev.20190507
Search Terms: any, unsound, extends, never
Code
Expected behavior: Either
bar.prop
should have the type"isAny"|"isNotAny"
orfoo
should not be assignable tobar
.Actual behavior:
foo
is assignable tobar
andbar.prop
has the type"isAny"
which is incompatible withfoo.prop
's"isNotAny"
.Playground Link: link