Chapter 1: Why TypeScript?

   



This article kicks off an in-depth guide to TypeScript for those coming from JavaScript. Many developers are confused when they come across new concepts like static types, inference, or decorators.

In this series of articles, we will explore the concepts and techniques of TypeScript to gain the benefits and uses of this tool.

🔗 Do you like Techelopment? Check out the website for all the details!


JavaScript: Powerful but Risky

JavaScript is an extremely flexible language, and it is also one of the most widely used in the world. Thanks to this flexibility, you can write code quickly without worrying too much about the formal details. However, this very "freedom" is also one of its greatest weaknesses.

Have you ever written anything like this?

function sum(a, b) {
  return a + b;
}

sum(5, "3"); // "53", not 8!

No errors. But that’s probably not what you wanted.

JavaScript lets you do potentially wrong things without warning you. This is the weak point where TypeScript comes in.


TypeScript: An Ally, Not an Enemy

TypeScript was created to help you, not to complicate your life. It is a superset of JavaScript, that is:

  • All valid JavaScript code is also valid TypeScript code.

  • You can continue to use everything you know.

  • But you can add type information to get more security and intelligence from the tools.

Example with TypeScript:

function sum(a: number, b: number): number {
  return a + b;
}

sum(5, "3"); // Error: Second argument must be a number

This time the error is detected before execution, directly from the editor or during compilation.

There is no need to wait for the code to go into production to notice the problem.


Practical Benefits of TypeScript

  1. Avoid common bugs before execution

    • Drastically reduces type errors

    • It helps you understand if you are passing or receiving the right data

  2. Smarter editors

    • Autocomplete (IntelliSense)

    • Faster navigation in the code (Go to definitionFind references)

    • Safer refactorings

  3. More readable and self-documenting code

    • If you see a function like this:

      function getUser(id: number): User { ... }
    • You already know what kind of parameter to expect and what kind of object it returns.
    • You don't need to read the entire body of the function.
  4. Easier to work in a team

    • If you work in a team, having types means:

      • Understand other people's code better

      • Avoid misunderstandings about how to use a function or class

  5. Great for large, structured projects

    • As a project grows, lack of types becomes a problem.

    • TypeScript scales well and keeps code maintainable over time


Why is it becoming so popular?

  • It is officially supported by major frameworks such as Angular, NestJS, and increasingly adopted in React and Vue environments.

  • It has become the de facto standard in enterprise projects.

  • Most popular JavaScript libraries now offer files .d.ts (type definitions) to better integrate with TS.

  • It is increasingly requested in job interviews: those who know TypeScript are perceived as better prepared on structured code.


In summary

TypeScript is not another language you have to learn from scratch. It is an enhancement to JavaScript, helping you write safer, clearer, and more robust code.

Most importantly: it doesn’t force you to type everything right away. You can introduce it progressively, even in existing projects.



Follow me #techelopment

Official site: www.techelopment.it
facebook: Techelopment
instagram: @techelopment
X: techelopment
Bluesky: @techelopment
telegram: @techelopment_channel
whatsapp: Techelopment
youtube: @techelopment