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

AI assisted search-based research actually works now

via Simon Willison

Changing Paintings: 67 Circe and her swine

Ulysses visits Circe's island, where his crew are turned into swine. When she tries to do the same with him, he refuses. They marry and spend a year together.

via The Eclectic Light Company

I'm on GitHub Sponsors

If you wanted to give me money but Patreon was causing grief, I'm on GitHub Sponsors now! Help me reach my goal of saving the world from AI scrapers with the power of anime.

via Xe Iaso