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
-
-
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 -
-
-
It's a it of duplication, but you can get the errors with typescript today if you enforce it's length const nums: [1, 2, 3] = [1, 2, 3]; const num: number = nums[4]; // fails And it's been marked for revisiting to have this behaviour by default
https://github.com/Microsoft/TypeScript/issues/24350 …Thanks. Twitter will use this to make your timeline better. UndoUndo
-
-
-
Definitely, that would make Typescript way safer ! Also, a pipe operator and optional chaining would be great
Thanks. Twitter will use this to make your timeline better. UndoUndo
-
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 