4 ms·
It's best to leverage type inference if possible. I can point to entire TypeScript files that could be copied and pasted into a JavaScript file and work with no
by d357r0y3r 7y ago
It's best to leverage type inference if possible. I can point to entire TypeScript files that could be copied and pasted into a JavaScript file and work with no changes.
At some point, yes, you have to use annotations to get the most of it. But, ultimately, I'd much rather trade the additional characters now for the alternative: insanity producing runtime errors in production later.
- sbr464 7y agoDefinitely agree, I just do it temporarily, typically when working on huge features.
- 013a 7y agoThe big problem with type inference, at least at API boundaries, is that its hard to tell who's "fault" an error might be. FuncA() returns T1, inferred. FuncB() expects it to return T2. Is FuncB expecting the wrong thing? Or is FuncA returning something incorrect? Always annotating the return types fixes this. That's one area that I think inference is always risky.