Most of us may have heard that TypeScript is a "flavour" or "variant" of JavaScript.
TypeScript is an open-source programming language that is a superset of JavaScript, meaning it adds additional features and functionality to the language.
It includes optional static typing, classes, interfaces, and other features that help developers write more maintainable and error-free code.
TypeScript adds additional syntax to JavaScript to support a tighter integration with your editor and hence make error checking easier.
TypeScript: A typed Superset of JS
This means that TypeScript adds rules about how different kinds of values can be used. Eventually, TypeScript code gets converted to JavaScript, which runs anywhere JavaScript runs.
TypeScript understands JavaScript and uses type inference to give you great tooling without additional code.
Wasn't JavaScript enough...?
JavaScript has its own oddities & surprises.
JavaScript is dynamically typed. In other words, until a variable is instantiated at runtime, JavaScript cannot know what type it is.
But in some scenarios, this may be too late. And if a variable is falsely assumed to be a certain type, this can cause significant bugs and accordingly, TypeScript adds support for the loosely typed JavaScript.
Type safety with TypeScript
As the name suggests TypeScript is all about type safety or you can say TypeScript is a Static Type Checker.
Detecting errors in code without running it is referred to as static checking.
TypeScript checks a program for errors before execution and does so based on the kinds of values, it’s a static type checker.
Why do we need TypeScript?
We need TypeScript because it can catch errors at compile-time instead of runtime, making it easier to find and fix bugs.
It also improves code readability and maintainability by making it more self-documenting, and it provides better tooling and editor support for large-scale projects.
Additionally, because TypeScript is a superset of JavaScript, it can be easily integrated into existing JavaScript projects.
Thanks for Reading!
Hope you enjoyed reading this blog and found it useful...