We've encountered an issue while upgrading our project from typescript2.4 to typescript3.2 specifically with immutable.js.
Prior to the update, simply using
if(x instanceof Immutable.Iterable)
would result in the type of x
being Immutable.Iterable<any, any>
within the if
block. However, post-update, the inferred type of x is {}
.
Check out this code snippet here: https://i.sstatic.net/So3re.png
Here's an example of the wrong type inference: https://i.sstatic.net/RGzCp.png
It seems cumbersome to resolve all the errors by explicitly casting
x as Immutable.Iterable<any, any>
.
Our suspicion is that the issue lies within immutable.js, as other types are inferred correctly within the if
block.
P.S. We are aware that instanceof
may not always be reliable (https://github.com/facebook/immutable-js/issues/450#issuecomment-107238770), and using Immutable.Iterable.isIterable()
does not provide the necessary type support, as the variable remains of type any
.