This article was originally published on .cult by Piumi Gunawardhana. .cult is a Berlin-based community platform for developers. We write about all things career-related, make original documentaries and share heaps of other untold developer stories from around the world.
What is TypeScript?
TypeScript is an open-source programming language rich in many features like inheritance, classes, visibility scopes, namespaces, interfaces, unions, and other modern features along with static and dynamic typing. It allows comments, variables, functions, statements, modules, and expressions.
Being a strongly typed programming language, TypeScript allows easier debugging (during the compilation), which is a more effective approach to codingfor complex applications.
Why TypeScript Emerged?
|Supports dynamic web page content|
The language is interpreted, therefore errors are only discovered during runtime
Weakly typed, no choice for static typing
Can be used directly in browsers
Modules, generics, and interfaces are not supported
Does not support optional parameters
Numbers and Strings are used as interfaces
Massive community support, including extensive documentation
There is no support for prototyping
No prior scripting knowledge is required
No need to set up a build environment
During compilation errors can be detected and fixed
Strongly typed; both static and dynamic typing are supported
Converts code to JS for browser compatibility
Supports modules, generics, and interfaces
Optional parameters can be added to functions
For static type definitions, a proper build setup (npm package) is necessary
Numbers and strings are objects
Community support is growing, not as strong as it once was
Prototyping is a viable option
Learning and coding takes time, scripted knowledge is required
Complexity is a key factor to consider.
TS makes code refactoring much easier and also emphasizes more on explicit types allowing the developer to grasp how various components interact. As it supports compile-time debugging, there’s a definite benefit to organizations working with large complex applications.
Setting up TypeScript for any project is straightforward. Some frameworks like Angular use TypeScript by default. So, in my opinion, TypeScript is the clear winner here.
Disadvantages of TypeScript
Despite the many advantages that TypeScript provides, it also has certain disadvantages.
When should you migrate your project to TypeScript?
When the code grows in size, complexity, and error proneness, it is preferable to identify specific problems during the compilation process. That’s where TypeScript comes in handy.
TypeScript also has interfaces and access modifiers that allow developers to collaborate and interact on a single codebase. Therefore, it’s probably best to use TypeScript from the beginning of your project.
Personally, I’m a fan of TypeScript and generally recommend using it for new projects. A little more effort at the beginning to save a headache down the road makes a lot of sense to me.
I hope that this article has helped you get a better understanding of the differences between these two scripting languages. At the very least, you’ve got a better understanding of what exactly TypeScript is (if you didn’t already know). Now you can make a more informed choice for your next project ;)