August 2, 2026

Deferred dreams, instant drama

Adding Go's Defer to the TypeScript Compiler

Coder tries to sneak a Go trick into TypeScript and the comments instantly start fighting

TLDR: A developer successfully hacked Go’s cleanup-after-you’re-done feature into TypeScript, then decided it’s probably not a good idea. Commenters instantly split into camps: some called the old-fashioned alternative perfectly fine, others worried debugging would get ugly, and Go fans begged for it anyway.

A programmer went on a very nerdy joyride: could they add Go’s beloved defer feature to TypeScript, the language many developers use to make big JavaScript apps less chaotic? In plain English, defer means “do this cleanup step automatically when the function ends,” which can keep messy setup-and-cleanup code together. The wild part? After hacking it into the compiler, the author basically came away saying: yeah, this probably shouldn’t exist. That alone was enough to light the fuse.

The comment section immediately turned into a classic internet language war. One camp was basically yelling, “Excuse me, try/finally was here first!” after the article called existing cleanup code a hack. That take from throwaway81523 had strong “kids these days don’t know their elders” energy, and it’s easily the spiciest disagreement in the thread. Another commenter, fg137, brought the practical panic: if this gets transformed behind the scenes, will error messages and debugging become a total nightmare? Translation: cool trick, but who wants their app to become a crime scene.

And then, of course, the Go fans arrived. One developer cheerfully dropped a link to their own package, yaplib, and declared that defer is the thing I miss the most coming from Go. So the vibes were split between nostalgia, skepticism, and “please do not make my tooling weirder.” In other words: exactly the kind of programming drama the internet lives for.

Key Points

  • The article presents an experiment to add Go-style `defer` semantics to the TypeScript compiler.
  • It explains that TypeScript currently relies on constructs such as `try/finally` for resource cleanup and does not have a strict equivalent of `defer`.
  • The proposed implementation adds a new `DeferStatement` to the parser and checks that it is inside a function body, not in generators, and that its operand is a call expression.
  • The compiler lowering strategy rewrites function bodies to maintain a stack of deferred callbacks and executes them from a surrounding `finally` block.
  • After completing the experiment, the author says they were convinced the feature probably should not exist in TypeScript.

Hottest takes

"it's the other way around? Try/finally is more traditional" — throwaway81523
"Would call stack/source map reasonably work with this?" — fg137
"defer is the thing I miss the most coming from Go" — geostyx
Made with <3 by @siedrix and @shesho from CDMX. Powered by Forge&Hive.