Learning TypeScript

| View comments on Hacker News

TypeScript is one of my favorite languages. It is fast, portable, has a great ecosystem, and the language itself is pleasant to work with. It has flaws, but I cannot think of a more versatile language. With TypeScript (and JavaScript), you can write:

  • Web applications
  • iOS/Android mobile apps
  • macOS/Windows/Linux desktop apps
  • Scripts
  • Backends
  • Games

I can’t think of another language so omni-present today. In a way, it’s like C. JavaScript, like C, can run anywhere since every platform has a web browser.

I’ve spent a lot of time becoming better at TypeScript, so I thought I’d compile and share some resources that have helped me over the years.

Unfortunately, TypeScript is complex. First, since it compiles to JavaScript, you need to learn that first. If you’re planning on writing frontend applications you’ll need to also learn HTML/CSS and Browser/DOM APIs. For backend you’ll need to understand NodeJS (or Bun/Deno).

Learning JavaScript is a pretty difficult task, even if you’re an experienced programmer. It has a strange inheritance model, it’s single-threaded, and the ecosystem evolves very quickly. I found the following to help me gain a better understanding of JavaScript:

Now, onto TypeScript! There are two things to look at: programming with TypeScript, and writing type-level TypeScript.

Reading through the TypeScript Handbook helped me understand the core features of the language.

The more difficult part is type-level TypeScript. This refers to writing programs in the type system to generate other types. This is where the strenght of TypeScript lies, since it allows you to precisely express the types of your program. Type-level TypeScript is also a large part of what made the language successful, since it allowed complex, dynamic, JavaScript types to be represented accurately.

The TypeScript Handbook has a section on type-level programming. This is a great reference, but I found the Type-Level TypeScript course to be the best resource. Matt Pocock, who is well-known in the TypeScript world, also has a series called Total TypeScript. I’m sure it’s execellent, but it costs hundreds of dollars, so it’s hard for me to recommend.

For additional challenges I’ve found Type Challenges to be excellent, especially with the VS Code extension.

Additional Resources

  • TypeScript on Exercism
  • Effective TypeScript
  • Runtimes:
    • Deno: Run TypeScript without compiling!
    • Bun: Similar to Deno. Also excellent.
  • Cool libraries:
    • Zod: Validate TypeScript types at runtime
    • ts-pattern: Pattern-matching for TypeScript
    • Astro: Tool that excells at static site generation with amazing TypeScript support
    • Remeda: Lodash for TypeScript
    • XState: Over-complicated state machines in TypeScript

Recent posts from blogs that I like

From the Commedia dell’Arte to Punch and Judy 1

Pierrot, Harlequin and other characters from the early professional theatre seen in paintings by Watteau, Goya and others.

via The Eclectic Light Company

Bloom filters

The original motivation for the creation of Bloom filters is efficient set membership, using a probabilistic approach to significantly reduce the time and space required to reject items that are not members in a certain set. The data structure was proposed by Burton Bloom in a 1970 paper titled "Spa...

via Eli Bendersky

Two publishers and three authors fail to understand what "vibe coding" means

via Simon Willison