Hacker News new | ask | show | jobs
by johnfn 3275 days ago
I'm pretty sure all weak typing warts basically stem from equality checks with ==/===. If you use === all the time you'll never run into them.

TS has optionals so undefined is not an issue.

The rest is valid.

2 comments

There are also some JavaScript functions like isNaN that also do type coercion and of course +. How is this handled in typescript?
In a word, "correctly". The result of an expression with + or isNaN() will be of whatever type the JS spec says it should be. This is one of the less frequently touted, but more useful aspects of TypeScript - the lib.d.ts file acts as a partner to explain to you how the built-in JS type system actually works without you having to memorize or look up everything in docs.
By optionals I assume you mean null and undefined types, not optionals in the Scala or Swift sense.