Hacker News new | ask | show | jobs
by zamadatix 2112 days ago
Again how can you say it's an outrageous default if all you reference is what you think it should have done from a generic language PoV not looking to understand why it does it that way?

Javascript came in as a scripting language for working with the untyped string content of a browser so you get dynamic duck typing where it tries to make the types work (generally towards string since that's what the browser had) instead of having the scripter trying to make some simple web content dynamic do more type checks than actual code. In JS functions are just objects (like most everything) and objects. Combine the above so when you say object + "foo" it coerces object to string and it shouldn't seem outrageous just not what you're used to.

Now a fair question would be "Why doesn't TS consider this an error out of the box".

Also for those annoyed by this in places JS wasn't originally designed to go (heavy app logic, server backends, desktop applications) you might want to look at the no-implicit-coercion rule in ESLint or similar.