Hacker News new | ask | show | jobs
by torben-friis 2559 days ago
Typescript has been useful for my team to reduce the number of unit tests and constant checking of number and order of parameters in functions, presence of null/undefined values, etc - when compared to JS obviously. It works particularly well when coupled with JSON schema validation that checks that the contract of your api is not ignored (TS types map very easily to and from JSON schemas).

As for your third paragraph, we follow some degree of functional programming precepts, which implies we avoid mutability as much as possible, so I can't comment much on the problems of mutating TS. I enthusiastically recommend pursuing immutability though, TS or not.

1 comments

I still don't get it. You can also add rigorous schema validation to your API endpoints with plain JS so you don't need to worry about strange inputs in your tests either. This is not unique to TS.
Perhaps I didn't explain it well - my point was not that you need TS to validate your inputs, it was that you can use TS to guarantee internal consistency of data, and that said internal consistency will work well as long as you ensure that the input is safe -which you do need to implement through other means like json schema. What TS offers in this context is to ensure that you didn't call a function with arguments present in the wrong order, that you didn't assign one variable instead of another, that you didn't forget to include one last argument...

All things that come up relatively frequently in vanilla JS during refactoring processes.

Yes, but it feels like more work and it's more verbose. In Typescript, it's also more or less convention, where as in JS it's just nice to have. I have less guesswork to do with Typescript. There's value in that.