Key Concepts in TypeScript
There are three things that make Typescript so useful:
- Classes and OOP
- boosting your confidence
- catching errors before they reach production
- making it possible to refactor code
- saving you time from writing tests
- giving you a good coding experience
When working with new codebases and in larger teams, TypeScript will give you more confidence. You will be less concerned if you are familiar with TypeScript and join a new team or project that uses it. You can count on TypeScript to help you out. Because you can look at something and quickly infer how it works, the language improves code readability and predictability. The type system is to blame for this.
Because TypeScript will detect errors for you, refactoring code becomes easy. When you rename a function, it will warn you if you fail to use the new name someplace else. TypeScript will correct you if you change the form of an interface or type and eliminate a property that you thought wasn't being utilised.
In essence, TypeScript is a JS linter. Alternatively, JS with compiler-friendly documentation.
Nevertheless, even if you don't use TypeScript to its full potential, it's a useful tool to have in your toolbox. It's simple to start small and gradually expand your capabilities, learning and adding new features as you go. There's no need to be terrified of TypeScript because it's practical and accommodating to beginners.
Top comments (12)
Once you go Typescript you never go back.
💯 agree with that, at least with relatively bigger projects
I just converted a large backend API from JS to TS.
I cannot count how many bugs I could fix out of the box, just by all the places where non-existing object properties were accessed, function parameters were omitted etc.
Exactly that :)
Another thing to keep in mind is that TypeScript is not a replacement for tests. Unit tests, integration tests, contract testing, e2e testing, etc... are all still incredibly important and should not be skipped.
Not true. I’ve turned TS “on” in more than one project and it has refused to compile without code changes.
That’s not true with TypeScript or any other strictly-typed languages, even Rust.
Many many types end up being weak little abstractions of otherwise very simple objects. The excessive abstraction makes the codebase harder to infer how things work.
And about the multiple points about refactoring being easier. That's truthy, but this is only a win in the sense that poorly designed software is a little easier to maintain. If there’s any doubts after a refactor, it is a sign of poor design regardless of language.
About your other points - direct them to the author:)
Hopefully this is just bad English.
"saving you time from writing tests"
Nothing, except ignorance, should save you from writing tests! If you're not writing tests, then don't push.
As most likely do, I struggled with TypeScript at first. But now, several months in, I kind of feel naked and unprotected without it. It's my default now.