DEV Community

Discussion on: The Trouble with TypeScript

Collapse
 
ryansolid profile image
Ryan Carniato

From what I've read that is a lot of people's experience. Of course, I write code that has errors but they are usually easy to classify and fix. There is that 2% that aren't logical or that aren't obvious at a glance I feel TypeScript might catch. But this waiting until I'm done to run through things definitely feels slower. After a while, it actually feels that even those 2% are classifiable without heavy debugging by learning what the symptoms look like.

I've refactored large projects across multiple modules without types many times. It looks a lot like aggressively changing everything and then everything is broken. And then you work piece by piece to get things working again. I know that terrifies some people (including my developers) but my mentors did similar things, and I have found that while you can introduce bugs the process is much faster since you aren't getting hung up on those details early on. Even removing TS from the equation, I've found less experienced developer's timidness in refactor being a gigantic slowdown. And there are tests for the rest. Tests have value regardless and I feel that TS should not be a reason to write less tests since runtime is the only truth.

And that's the thing I don't think using TypeScript feels slow. I think that the process/ceremony it pushes you towards can be slower than just doing things and trying as you go. It may not be in all cases but I don't believe it's so cut and dry to be like "improves" productivity.

Collapse
 
juliang profile image
Julian Garamendy

I realise I've never worked on a large JS project (only TS). So perhaps I don't really have real-life examples to compare.

I agree the ability to refactor is more related to test coverage (of use cases) than to having types or not.

I just never felt slowed down by TypeScript, and I did when I worked on (even small) projects using only JS because I need to load the "types" or object-structures in my head instead of letting my IDE and type checker do it for me.

I never had to ask myself:

What's the shape of the object this function is expecting?

because in TS you can't get it wrong. My IDE will highlight it in red as I make a mistake.

I only add type annotations where strictly needed, I let type-inference do the work for me.
I don't spend much time writing types.

I'm not sure what's the process/ceremony you mentioned.

Cheers!