Flow version: 0.278.0
Expected behavior
function fn<T: string>(str: T): void {
str as (T extends string ? T : T); // works
str as (T extends number ? T : T); // should work but errors
}
Actual behavior
3: str as (T extends number ? T : T); // should work but errors
^ Cannot cast `str` to conditional type because string [1] is incompatible with conditional type [2]. [incompatible-cast]
References:
1: function fn<T: string>(str: T): void {
^ [1]
3: str as (T extends number ? T : T); // should work but errors
^ [2]
I understand this is a very contrived example, but I was trying to come up with a minimal reproduction that demonstrates the issue clearly. We've hit this in real code, and I used something closer to a real example in the Try-Flow below.
- Link to Try-Flow or Github repo: Try-Flow
Flow version: 0.278.0
Expected behavior
Actual behavior
I understand this is a very contrived example, but I was trying to come up with a minimal reproduction that demonstrates the issue clearly. We've hit this in real code, and I used something closer to a real example in the Try-Flow below.