Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

== versus === and all the other weak typing wats, undefined type still exists in typescript, no integer type, UTF16 strings are the ones coming to my mind and I don't even program in JS/TS


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.


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.


For == vs === use a linter, same as you would for warts in other languages.

What's the issue with undefined - is it that you would use null instead?

I don't feel a need for integer type, but maybe that's because I grew up on JS. Integers feel like warts to me in a lot of cases, ie why would 2/3 == 1?


2/3 === .666666666666666629659232512495 is probably worse, because it can seduce you into thinking it's accurate. Why is `2 / 3 * 3 === 3`, but `1 / 3 * 3 < 3`?

JS's floating-point-or-bust, combined with some weird Math semantics, makes it challenging to write numerically correct functions.


That's a fair point. Which language do you think does it better, or is there a library you like to use (eg. Haskell's scientific type)?


Floating point tends to break all sorts of assumptions. For languages without static types, bignum integers and distinct operators for truncating vs FP division is probably best. This is how Python 3 works, plus Haskell and SML (with static types).




Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: