You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
(This is very weird code, result of reducing a real-world situation to the minimum complexity necessary to reduce this.)
classA<Value>{prop!: (x: Value)=>void}classB<Value>{prop!: A<Value>is<T>(): this is B<T>{returntrue}}letb: B<any>=nullasanyif(b.is<string>()){// b will still be of type B<any> here}
Expected behavior:
The conditional would, due to the type guard on the is method, narrow the type of b to B<string>.
Actual behavior:
b remains of type B<any>. But, when the line that defines A.prop is commented out, it does correctly get narrowed to B<string>. If its type is changed to just Value, or some function type that doesn't involve Value, the problem also goes away.
TypeScript Version: 3.8.3
Search Terms: guard recursive
Code
(This is very weird code, result of reducing a real-world situation to the minimum complexity necessary to reduce this.)
Expected behavior:
The conditional would, due to the type guard on the
is
method, narrow the type ofb
toB<string>
.Actual behavior:
b
remains of typeB<any>
. But, when the line that definesA.prop
is commented out, it does correctly get narrowed toB<string>
. If its type is changed to justValue
, or some function type that doesn't involveValue
, the problem also goes away.Playground Link: here
Related Issues: none that I found
The text was updated successfully, but these errors were encountered: