Hacker News new | ask | show | jobs
by d357r0y3r 2616 days 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.

2 comments

The 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.

Definitely agree, I just do it temporarily, typically when working on huge features.