TypeScript And The Enterprise

TypeScript, the nearly decade-old Microsoft project, increases in popular by the day. What is it?

TypeScript is a typed superset of JavaScript that compiles to plain JavaScript.

It offers the many benefits of JavaScript with the safety of types. The ThoughtWorks Radar explains the hype:

Large-scale projects benefit most from the type safety. Our developers favor its minimal configuration management, well-integrated IDE support and its ability to refactor code safely and gradually adopt types.

ThoughtWorks marked TypeScript as “adopt” in early 2019. Here’s a few reasons why, when compared to JavaScript, the technology is a good choice today:

  • Prioritizes reliable software: TypeScript alleviates common JavaScript runtime bugs by encouraging developers to handle errors at build time, reinforcing a program’s correctness and ensuring users encounter less crashes. Strong typing permits sweeping refactors and rewrites with safety.
  • Quality developer tooling: IDE features like code completion, symbol lookup, and inline compiler errors are a huge productivity boost, and TypeScript’s robust type system makes them possible. TypeScript’s language server is so good that it can partially provide these features to plain JavaScript in Visual Studio Code.
  • Less testing required: A typed language largely eliminates common unit and integration tests around parameters and return values. This also benefits the runtime: typings remove the need for libraries like prop-types, resulting in smaller bundles.
  • Bright future: TypeScript quickly adopts the latest ECMAScript specification with powerful typing primitives. This allows developers to use tomorrow’s language features today, and ship code that runs in any JavaScript environment.

The Enterprise

Engineers at large companies choose to author their web user interfaces, services, and native applications in JavaScript. Adopting TypeScript poses unique advantages at enterprise scale.

Experienced and junior engineers alike want to use TypeScript: senior practitioners recognize its value, and newbies know of its increasing importance in the industry. Adopting this upcoming technology and training your company’s engineers on its use can be a big motivator in hiring and skill retention.

Applications written in TypeScript tend to be less prone to bugs, but there’s some additional benefits for large teams:

  • Quicker on-boarding: Engineering resources shift drastically depending on the business’s needs: new teams form and existing teams change focus to ensure priority projects ship. TypeScript’s types serve as additional documentation on internal application state, data schemas, and data transformations of the program; types can help answer the ”why” questions that newcomers often have. Coupled with type safety, it helps newcomers confidently ship code.
  • Accelerated development: Time to market is incredibly important at the enterprise level, and TypeScript can be a competitive advantage, as my team observed with Walmart’s Baby Registry.
  • Manage technical debt: Enterprise software often contains feature-rich, long-lived code bases, a recipe that makes continued development increasingly difficult. TypeScript especially shines in large programs, where its safety mechanisms can guarantee new code doesn’t break the system and internal refactors don’t break public-facing interfaces. The act of adding types reveals similarities between disparate pieces of code, which can lead to useful refactors.

TypeScript can foster cross-team collaboration, an important yet often fleeting goal at companies with hundreds of engineers. This begins with a joint effort in typing the company’s microservices and APIs in reusable packages, and continues to community rewrites of shared code bases. A typed language also presents a more inclusive code base for practitioners of traditional enterprise languages (Java and C++): I’ve witnessed these engineers willingly contribute to TypeScript code bases.

Means of Adoption

TypeScript supports incremental on-boarding of projects, with increasing improvements in safety and developer ergonomics at each step. This favors teams adopting the technology at their own pace. A rough outline of how this looks:

  1. Installing and configuring the compiler
  2. Porting JavaScript files to TypeScript files, adding type annotations
  3. Opting into stricter checks
  4. Progressively removing loose type definitions

TypeScript adoption becomes easier for application teams if the shared code layer (UI components, service clients, utility libraries, etc.) offer support via rich types: this ensures developers get all the advantages of building on a typed ecosystem without the additional burden of handling these types in each code base. Rewriting shared code in TypeScript is preferred: it ensures accurate types for consumers and will guaranteed surface a host of bugs in the common layer.

Embracing TypeScript at enterprise companies comes with a cost: refactoring existing JavaScript to TypeScript in code bases is non-trivial, and it takes time for engineers to learn a new tool. However, the advantages of more reliable software for users, tooling that engineers enjoy, faster on-boarding, improved handling of large code bases, and the potential to build a cross-team community are worth it.

Enthusiastic about TypeScript? Great news: we’re hiring in Portland, Oregon. Check out our job listings on careers.walmart.com or shoot me an email for more details.