Why I love TypeScript and why you should too!
https://www.istockphoto.com/portfolio/mirsadsarajlic?mediatype=photography

Why I love TypeScript and why you should too!

I’ve been coding JavaScript through the browser wars and long before jQuery’s first release. I resisted enhancements to the language that encumbered my ability to write code quickly, especially TypeScript introduced in 2012.

Having started my career writing C++ and Java code, I found JavaScript refreshing, freeing me from the cognitive load of these strongly typed languages.

When I saw Microsoft Web Apps, which included Excel and Word, written in JavaScript, running in the browser I was convinced that strongly typed languages were overrated.

Today, I have a new rationale for using TypeScript.?

As Agile and TDD have become mainstream, one of the most important tasks of a developer is code refactoring. The challenge is to refactor code without introducing defects or slowing down the developer. When refactoring, breaking changes can go undetected by your unit tests.?

When your code is adequately typed the compiler fails on breaking changes and informs you what code needs to be updated even when your unit tests don’t. TypeScript makes your code more self documenting and adds a layer of intelligence that tests do not provide.

TypeScript can be added incrementally, as needed. For example, when a TDD test requires a code change consider migrating the affected source files from .js to .ts. The compiler will tell you which functions need typing. Add the types or opt out of typing by adding the “any” type.

Also, the Agile team can design the types as part of a task breakdown exercise which helps build consensus around the solution and improves overall code quality and cohesiveness.

Why type a typeless language?

This question has never been answered for me until I started using TypeScript.

The answer is two fold: 1) to ensure the developer understands what code is needed before writing the logic; and 2) to guard against breaking changes and enable a robust refactoring experience.

I often write pseudo code to develop clarity of mind about how to implement a feature. My pseudo code looks a lot like TypeScript! So replacing my throw away pseudo code with TypeScript, a powerful validator and documenter of my code’s intention, was a small change in my coding style.

TypeScript allows me to work smarter. As I refactor my code the compiler tells me what I broke and how to fix it! TypeScript allows me to type when and where I want. It makes my code better by encouraging Agile and TDD practices, and protects my code from breaking changes.

I found TypeScript improves my productivity, too, but sometimes I just need to code without typing and it is this flexibility that I love.

Kelly Seager

Whirling Dervish Music: Singer-Songwriter, Music Teacher & Music Production & Recording

1 年

I have absolutely no idea what you are talking about, but I enjoyed reading your analysis… I hope you are doing well! ??????

要查看或添加评论,请登录

Douglas Ross的更多文章

社区洞察

其他会员也浏览了