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

Hero or hooligan: The cunning of Odysseus

King of Ithaca, he first feigns madness to dodge going to war against Troy, but then uses his cunning and ingenuity to design the Trojan Horse and conquer the city. Runs into trouble with Polyphemus during the return journey to Ithaca.

via The Eclectic Light Company

taiwan travelogue

a review

via bookbear express

Impro is a handbook for running a cult

Here’s the big idea in Keith Johnstone’s book Impro:

  1. Children are naturally creative, but are violently formed into repressed adults by Western culture and education
  2. The process of becoming more creative and expressive is largely a process of unlearning these habits of repression
  3. Improv — improvisa...

via Sean Goedecke