If you're a developer, and you have been hearing about Typescript and thinking to yourself do I need to learn it? Well if this is you stick around and let me give you reasons to learn typescript. But before we get there let us discover what typescript is
So what is Typescript you say? According to the Official typescript documentation, TypeScript is a strongly typed programming language that builds on JavaScript, giving you better tooling at any scale. But to give a broader explanation Typescript is an open-source programming language developed by Microsoft in 2012, it is a superset of JavaScript and it also compiles to JavaScript which means it can run anywhere JavaScript can run. It sounds fun, right? Well, let's get into some of the major benefits of using typescript.
Typescript enforces optional strict typing: Basically, it ensures that your variables and functions remain what they are once declared, for example, a number can only be passed to a number variable while a string can only be passed to a variable that is typed as a string. This is very useful for reducing errors because typescript will catch type-related mistakes for you during compilation before it gets to production. Prop types used with react is a package that works very similarly to react in performing type checking but of course, typescript is much more extensive
Typescript helps in catching common bugs early: Because code is run through a compiler, typescript catches about 15% of common bugs made that JavaScript would not normally catch which can save a percentage of developers' time.
Predictability and Readability: When you are using typescript, you can be assured that everything remains the way it was declared to be, this increases the likelihood that your code and functions run the way they are meant to be. Explicitly defined data structures and type annotations make it much easier to understand the decisions made by the engineers originally writing your code.
Well, these are some of the benefits of using typescript but you need to use it to understand why and how it works. I didn't really start to appreciate typescript until I went back to working on a codebase for a react project without typescript after months of working with typescript and my brain started to pick out errors in the code that typescript would have normally caught but JavaScript allowed which caused the code to break.
I asked a friend of mine who is an advocate for typescript and helped me when I was just learning typescript why he likes typescript and this was what he had to say.
- "Typescript on a fundamental level is just JavaScript with the extra ability to add type syntax. The first time I saw typescript in action I was excited about its ability to autocomplete or suggest parameters based on the types fed into it. Using it for the first time meant that I didn't always have to go through the documentation to check if a particular param exists as I did with JavaScript. I was able to extend this to my own by creating typed functions, what the functions expected and what they returned. This would throw an error whenever the criteria were not met and I would have to figure out what went wrong and how to fix it. Also beyond creating functions there were other data types and what you expected from them. Eg. a string, an array, a number, an array of strings, and that of a number. It provides type safety that eliminates a lot of errors you'd normally encounter in JavaScript before you even run it."*
I think in very simple terms it creates a great developer experience, especially during collaboration with a team, and other developers and on large-scale projects. Managing the codebase becomes efficient if a strict typing system is used. As other developers won't try to guess or manually check a data type or an error.