|
|
|
|
|
by gridlockd
2479 days ago
|
|
Why do people care about this? Writing type annotations is not that much work, but they make your code more readable. I can see the argument for it when you have unspellable nested generic types, or when you don't want to write the same thing on both sides of an assignment. Simple type inference like in TS gives you that. Having really smart type inference makes your compiler slower and more complicated. What's the real-world benefit? > Typescript will try to unify the type to some sort of Any, which is probably not what you want. Not really, unless you push the type inference beyond its limits, in which case you should just change your code. |
|
> Why do people care about this? Writing type annotations is not that much work (...)
I personally care about this when I'm prototyping something. Not having to write types means that I can simply write what's on my mind. The benefit of good type inference is that the compiler can still help me highlight any mistakes I made during this process.
Another benefit is that some production code can get very complex. Having to type every single value is just too cumbersome and distracting. It contributes to boilerplate and increases cognitive load, in my opinion.
> Having really smart type inference makes your compiler slower and more complicated.
I would actually disagree with this. First of all, ReasonML's compiler is absurdly fast. No, seriously try it. Sometimes I go and double check the generated JS code just to be sure it actually did anything.
Regarding the "more complicated" part – the only reason why full type inference works is because it is based on a very solid theoretical foundation. It might be somewhat "complicated", but it will never be as complicated as something ad-hoc that needs to account for all inconsistencies that exist in untyped languages like JavaScript.