But, as you might expect, and want them to, these cannot be just random things. These are based on types - a term not so popular in JS community. If you don't know what these are then google it and see you later. So, as you may already know types are awesome! (You may agree or not but I don't care.) They provide editor support and performance optimizations for typed languages if used correctly. But, (at least as far as I know), JS is not a typed language and it's kind of one of its main selling points. Of course, untyped languages have their own totally different pros but it's definitely not the editor support. For the time being it's not so easy to implement good autocompletion support without types. And because JS isn't becoming a typed language in the near future, some alternatives have appeared. One of which is TypeScript, a language or as I can call it "a thin typed layer" built on top of JS. This creation, with a name created by a nice game of words, is aiming to provide typed-like language experience without changing the base JS syntax. In addition, it adds support for some syntax sugar available in ES-next.
So... - "Long live TypeScript!" - right?
Well... not exactly. You see, TS looks just great from the top - no new syntax (if not counting the types, of course), editor support (VS-Code especially) and "backward" compatibility with JS.
You know what it means, right?
Backward compatibility is a property of a system, product, or technology that allows for interoperability with an older legacy system, or with input designed for such a system, especially in telecommunications and computing.
In this situation, JS isn't old or legacy - it's not important. The word interoperability is the key. In TypeScript, you can import the JS library, but it won't obviously magically generate typing for this particular code. That may not seem so, but becomes quite problematic when you want to use TS "full-potential" in its strict mode. Then you get some nifty errors (unless you hack your way through TS configuration) and no type-safety, which is pretty bad for my lacking. But don't worry d.ts (TypeScript Declaration) files are here to help! Of course only if you've got time to do a thing such as writing TS binding for some enormous library. Well, you're not alone here as well. Say hello to DefinitelyTyped where other people sharing the need with you have already covered many popular JS libraries. Sadly, not all (so unexpected) and that's the main problem. You can type something that is untyped from the beginning without doing anything. But apart from this and the fact that TS type system lack some (not really needed but helpful) features, then yes - "Long live TypeScript!" and actually, this statement is becoming reality.
At the time of writing this post, there are only two main competitors to TypeScript - Flow & JSDoc itself. As this wasn't meant to be about them, I'll make it clear:
- OSS made by nice guys from facebook;
- It's a type checker not a new language;
- Has similar typing system to TS;
- Supported in most of modern editors;
- Performance is a bit laggy, but fine;
- Has smaller type base than TS;
- Better support for React than TS;
- OSS project & kind of documentation standard;
- Implemented in form of comments in JS;
- No performance decreasement from normal JS;
- Different typing system that that of TS / Flow;
- Can be harder to create complex types than in TS / Flow;
- Supported in almost all editors;
- Documentation generator extra;
Personally, since I discover TypeScript I can't stop using it. The editor autocompletion support it provides is just mandatory for me. I tried to use Flow and JSDoc but honestly these weren't any better than TS (just my opinion). Of course, lack of typings for some libraries can be problematic but it isn't really something I can blame TS for. So my recommendation? Just pick one of the mentioned projects, whether it'll be TypeScript, Flow or just JSDoc if you haven't already and if you have, then don't forget to share this post to those who haven't. Have a nice, typey day.