Another “Why TypeScript” Blog Post & Excerpt

July 13, 2017 0 Comments

Another “Why TypeScript” Blog Post & Excerpt

 

 

This is an excerpt from my recently published and free book, Yet Another TypeScript Book. It’s hosted by the good folks at Gitbook here: https://pagalvin.gitbooks.io/yet-another-typescript-book/content/

The introduction to the book is your typical book intro and starts to make the case for why TypeScript is worth your time learning.

Here’s the excerpt:

For starters, at least one major framework, Angular 2+, pushes you hard into using TypeScript. If you work at an Angular shop, you have a strong practical reason to learn it. Other frameworks provide TypeScript-friendly features or vice-versa. For instance, TypeScript provides first-class support to React developers via smart JSX intellisense.

Some people might characterize “learn it because you need it for future dev work” as a “negative externality” and not exactly popular. That would be fair. But consider the fact that many pure JS library authors have worked hard to provide TypeScript-friendly interfaces. Here’s the DefinitelyTyped github project:

Check it out today and see how much it’s grown since March 2017.

At a high level, typings help bridge the gap between TypeScript and pure JavaScript libraries. I bring up the DefinitelyTyped github project because it shows a that a good-sized group of library developers and/or devotees think it’s worth their time to create these typings. As you can see in the screen capture above, with over 3,000 contributors, almost 27k commits and pushing 10k stars — the project offers some evidence that it’s worth your while learning about this.

All of this is to say that TypeScript has and continues to gain traction in the JavaScript community. The jury is still out as to whether it will “win” and become a truly mainstream scripting language for web dev. It probably won’t become the language of the web. But its appeal cannot be denied. A growing swath of current and future front end developers are choosing TypeScript over pure JavaScript. Some folks are even wondering if they should learn TypeScript alone and skip JavaScript altogether.

TypeScript’s growing popularity answers the “Why TypeScript” question in part. A lot of us aren’t swayed by popularity, however. I’m sympathetic to that point of view.

I came to TypeScript after spending about three or four years building solutions that contained minor to major bits of client-side code. I used jQuery for DOM manipulation and async work and lots of straight JS logic. I struggled with all the usual things at first, like closures or how to test for null or undefined and the family of "=", "" "=" operators. I eventually came to an uneasy understanding of these things but some problems never went away. I found it difficult to apply common design patterns with great confidence. Pure JavaScript is terribly difficult to refactor, even for trivial changes.

As you’ll discover in chapter 4, TypeScript is a statically typed language. Or at least, you can use types if you want. It’s much less ambiguous than pure JavaScript both from an “intent” perspective (“what did the programmer intend with this code?”) as well as straight-up technical meaning. Since TypeScript mitigates ambiguity, IDEs can provide better support. You’ll see many examples of this throughout the book.

These two points combine to make working with TypeScript a truly joyful experience. Closure complexities recede. It’s more difficult to accidentally assign strings to numbers. Refactoring isn’t as difficult so you’re likely to make necessary changes in a timely manner rather than pile on a little more technical debt. It’s a breeze to manage complex objects. TypeScript’s syntax maps nicely and neatly to many common design patterns.

For me, TypeScript is like starting to cook a large, complex meal in a freshly cleaned, well organized and well-stocked kitchen. You can focus on producing a beautiful meal instead of worrying over whether you have enough unexpired tarragon in your spice rack.

It is, simply, a joy.

</end>


Tag cloud