TypeScript Architecture
But why do we need to use TypeScript if it is almost the same as JavaScript?
JavaScript, initially a client-side language, expanded into server-side programming. Yet, its complexity hindered it from excelling as an object-oriented server-side technology. To address this, TypeScript emerged, bridging the gap and offering a more robust solution.
The biggest point of TypeScript is naturally “Type”!
Data in TypeScript requires explicit types, JavaScript does not.
In TypeScript, we need to explicitly define the types of variables, while in JavaScript, the types are inferred at runtime. This means that TypeScript can catch errors at compile time before the code is executed, while JavaScript can only catch errors at runtime. This can help to prevent bugs and make code more reliable.
This becomes particularly beneficial as codebases expand, preventing bugs and reducing complexity. Additionally, it enhances code readability for other programmers by providing clear input and output type expectations for functions. This clarity becomes even more crucial as functions grow in size and complexity.
Pros:
- Provides optional strong static typing
- Detect bugs earlier
- Code is predictable
- Extensibility and Reusability
- Provide object-oriented writing
Cons:
- There is a certain learning cost
- Need to write more code
- Need to compile