Harry Yates

I'm a web developer focused on TypeScript, React, and Three.js.

How TypeScript works

Thu, 15th Feb 2024

TypeScript is a superset of JavaScript that adds types to the language.

This means that any valid JavaScript code is valid TypeScript code.

TypeScript compiles down to JavaScript

The catch is that browsers don’t understand TypeScript. They speak pure JavaScript. So, TypeScript needs to be compiled, or "transpiled," down to JavaScript before it can be executed in a browser. This process strips away the TypeScript types, leaving clean, browser-friendly JavaScript behind.

Benefits of TypeScript
  1. Bug Prevention: By catching type-related errors early in the development process, TypeScript acts as a safety net, ensuring those bugs don’t make it to production. This can save hours of debugging and testing, making developers' lives significantly easier.
  2. Improved Editor Autocomplete: TypeScript’s knowledge of types enhances code editor's ability to provide accurate suggestions, speeding up the development process and reducing errors.
  3. Better Collaboration: Clear definitions of data structures and expected types make it easier for teams to work together on code, reducing misunderstandings and conflicts.
Challenges of TypeScript
  1. Learning Curve: For developers new to types or coming from a purely JavaScript background, TypeScript introduces a learning curve that can initially slow down development.
  2. Overhead for Small Projects: The setup and maintenance of TypeScript might not be worth the investment for smaller projects where the benefits don’t outweigh the initial overhead.
  3. Legacy Projects: Integrating TypeScript into existing JavaScript projects can be challenging, requiring a significant effort to refactor and type-annotate large codebases.


Cheers!