Hacker News new | ask | show | jobs
by javcasas 2309 days ago
I work with Haskell, a language that some people call "pinnacle of type systems". Guess what would happen if I use `unsafeCoerce`? Exactly the same that would happen if I use `<any>` in Typescript. All the type guarantees go out of the window.

In your code, if someone throws a bad class into the mix, it will blow up both in Typescript and in Java/C# and in any other programming language. But, somehow, blowing up in Typescript is way worse that blowing up in Java/C#. Go and tell me that when I'm not allowed to put `nulls` anywhere neither in Java nor in C#, because that's something I can do in Typescript today.

1 comments

Being able to ban null values is absolutely fantastic. That's definitely a big improvement over Java, and seeing it in Typescript makes me wonder why Java allows it. In fact, seeing Option in Scala made me wonder why anyone ever thought null was a good idea.

Even if it's only a compile time check, and can therefore still be circumvented at runtime, this check for null values has still helped me out a lot. At least within a class it ensures my assumptions are consistent, which is not nothing.