No JS tool (that I know of) will warn you about these conditions being impossible. But they should. const foo = 'FOO'; if (foo[0] === 'B') {} // impossible if (foo === 'BAR') {} // impossible
-
-
For arrays of unknown length, the type should be `?T`. You can support refinements of `arr.length` to avoid a majority of these.
Show this thread -
Also refinements should work with function calls: function isString(str) { return typeof str === 'string'; } declare var foo: string | number; if (isString(foo)) { foo; // foo has been refined to string here } else { foo; // foo has been refined to number here }
Show this thread -
And it should work across files, and shouldn't require a %checks annotation like in Flow.
Show this thread
End of conversation
New conversation -
-
-
I brought this up awhile back, and was directed to this issue. Apparently a common request: https://github.com/Microsoft/TypeScript/issues/13778 …
Thanks. Twitter will use this to make your timeline better. UndoUndo
-
-
-
You can do that, if you manually type the array (would be cool if it worked automatically, however)pic.twitter.com/k3wZL39TaG
-
New conversation -
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.
he/him 