What might the future hold in store?
The web has seen a massive increase in usage with individuals spending more than 6 hours per day online(!) This usage increase has lead to a demand in web development jobs as companies are looking to establish their presence online.
Before diving in deeper, let’s have a look at what JS and TS is.
The development community strongly associated TypeScript with Angular in the early days. That was because Angular forces you to use TypeScript, though overriding this is possible.
How Popular Is TS Now?
TS has been gaining massive popularity in recent years. The increase in popularity is quite astounding as it has climbed to the 4th rank as the language that has dominated over the years (source: octoverse). What is surprising is that TS was previously in the 7th position in 2019. This shows an increase of 3 ranks in one year which is remarkable.
Although this feat is impressive, it is far from the dominating JS ecosystem which was ranked as the most used language by Octoverse for several continuous years.
As Eliot says, TS can be considered as a really big wave in the much bigger ocean of JS.
If you observe both these programming languages carefully, you will notice that some of the new features introduced by JS have already been implemented by TS. Although it cannot be deemed as JS is copying from TS, but there is a possibility that TS influences JS to include features that are most sought by developers.
Let’s have a look at some of these features in JS that may have been influenced by TS.
Recent Changes in JS That May Have Been Influenced by TS
You can read more about it over here.
Optional Chaining is simply a feature that allows you to safely access deeply nested properties of an object without having to check for the existence of each of them. Optional Chaining uses the ?. operator to access the properties of objects. The usage of the ?. operator is very similar to the typical . operator, but when a reference is undefined or null, rather than throwing an error, it would return undefined.
This results in a simpler and cleaner code that guarantees no error will be thrown when exploring objects with uncertain properties.
You can read more about ES2020 Optional Chaining in my article over here.
Nullish Coalescing allows you to check for nullish values instead of falsey values. Nullish values are values that are either null or undefined . While falsey values are values such as empty strings, the number 0, undefined, null, false, NaN, and so on. This might not sound like much of a difference to you, but in reality, it means a lot.
Once we were introduced to the class syntax, which was introduced to give us the feeling of an OOP like language, we developers were wanting more OOP like features.
The upside is that this sort of “soft privacy” can help your consumers temporarily work around not having access to some API, and also works in any runtime.
On the other hand, ECMAScript’s # privates are completely inaccessible outside of the class. This hard privacy is really useful for strictly ensuring that nobody can take use of any of your internals. If you’re a library author, removing or renaming a private field should never cause a breaking change.
For those who know it, decorators are a handy feature that has been in use for quite some time. If you have been familiar with Angular, you would have noticed that there will be an “@Component” in your components. Similarly, you will find more of these strange symbols such as “@Injectable”, “@Directive” and more. These strange terms are called Decorators.
However, there is a new proposal that uses the “@” symbol to identify decorators. It is still under stage 2 of the TC39 proposal. Because of this, TypeScript has marked this feature as still experimental and requires you to enable flags or modify your tsconfig.json .
You can read more about decorators in my article over here.
Although these techniques can be considered as workarounds, it will be nice to have this feature implemented natively. The JS team can follow a similar approach to how they implemented classes and implement interfaces as syntactic sugar for “duck typing”.
You can read more about Duck Typing over here.
This is also a feature that has been introduced in TypeScript that was found to be very helpful. This feature was similar to namespaces in C# and packages in Java.
According to Addy, “Namespaces can be considered a logical grouping of units of code under a unique identifier. The identifier can be referenced in many namespaces and each identifier can itself contain a hierarchy of its own nested (or sub) namespaces”.
Although this might not be the most-wanted feature, I believe that the JS team would be able to provide this feature without much of a hassle.
Both TS and JS have progressed a long way from their humble beginnings. But in order for them to keep on growing, it is essential that they provide much-need features to their dev community, regardless of who provides it first.
What are the features you believe JS would “steal” from TS, or rather in other words, be “influenced” by TS? Mention them in the comments below.
Thank you for reading and happy coding.
Bit makes it simple to author, document, and share independent components across web projects.
Use Bit to maximize code reuse, speed-up delivery, and build apps that scale.
Bit supports Node, TypeScript, React, Vue, Angular, and more.
- React TypeScript: Basics and Best Practices
- What’s Wrong with Web Assembly?