4 ms·
I really dislike how unpredictable the typescript compiler can be. What I mean is, there isn’t a simple set of rules I can understand to know when annotations w
by pharmakom 4y ago
I really dislike how unpredictable the typescript compiler can be. What I mean is, there isn’t a simple set of rules I can understand to know when annotations will be required. Most of the time, this doesn’t matter, but occasionally it blows up and development comes to a screeching halt. Contrast this to, say, Java and ML type-systems, which are highly predictable.
- jcparkyn 4y agoI think the opposite, TS is much more predictable than hindley-milner inference, mostly because the inference only flows forward. Yes, there are a couple of weird edge cases with arrow functions in generics, and it gets a bit more complicated with narrowing, but aside from that this never a problem I've run into. IMO the verbose error messages for complex types are a much bigger problem, which could be solved with better UIs for error messages (syntax highlighting and code folding).
- culi 4y agoThe rule I tend to follow is "annotate as little as possible". This has worked out great for me so far since TypeScript's inference gets it right 90% of the time and it leads to more maintainable code. Also after coding 5 days a week for a full year with it I really can't relate to the idea that it is somehow unpredictable. I think, like most things, you eventually get a "feel" for it and don't even have to think about it. That's what I love most about it. It feels like it takes up no extra mental real estate for me. It's excellent at never "getting in the way" (when used properly)
- anileated 4y agoUse LSP feature that reveals what TS thinks is the type of the identifier under the cursor (I have it bound to Shift+K in Neovim). If not right, annotate (or better go back and type properly whatever means you obtained that value).