Advantages of TypeScript
So, in here if you can see, the function is expecting a number as id and it will return a Promise. Which immediately tells me that when I am calling this function it will have to be an async function or I will have to use the “then” function to resolve the response. And, also because of line number 12, I know that the promise will return me a Todo which I have defined as an Interface.
Debugging and Linting during development
As a developer, one thing which I love about development is the joy to see things building as I write code. Now, there will be cases when the code will have some issues. And, many times we do have issues – right?
Better component architecture
I also find that using TypeScript, I can structure my components a lot better. It’s very easy to define an interface for the Props and so any other developer will immediately know what data to send to the component and in what format. Also, if my component supports only specific types of value for a specific property, then I don’t need to write code for that. By declaring that in the interface, I can be rest assured that no other developer can send such a prop to the component.
These points may look small however, but they are strong enough to make a difference. I have seen a huge difference in how I write code now compared to when I was not using TypeScript. I can use someone else’s component with a lot more confidence which is a key factor while working with a team. If you are not already working in TypeScript then I will strongly suggest that you give it some time and I am sure you will love working with it.
Let me know what are your views about TypeScript? Whether you like it or not. If not what are the reasons and I would be very happy to jump on a conversation with you on Twitter maybe. My twitter handle is @amitavroy7.