Member-only story

How to Use TypeScript Decorators with esbuild

Ben Force
2 min readMay 12, 2023

--

Just about every developer that I meet has one, or more, side-projects that they work on. My primary side project (an Alexa skill called Movie Quiz) has helped me learn several new technologies over the years. Working on this skill has taught me everything from DynamoDB single-table design to CI/CD pipelines.

I recently learned about NestJS at work and the power of Inversion of Control and Dependency Injection. It just so happens that someone kindly added Dependency Injection to the framework that I use for my skill. Also, I’ve been having a difficult time getting some updates in the skill through certification, so it seemed like a good time to implement DI and write more some unit tests.

Issues with esbuild

Esbuild is a super fast typescript bundler. It gains this speed by completely ignoring the typescript. The problem with that is the Dependency Injection that I wanted to use relies on TypeScript Decorators. I had to turn on emitDecoratorMetadata and experimentalDecorators in my tsconfig file, but since esbuild just ignores that, all I get are errors.

Slowing Down esbuild

The solution was to get a plugin that negated all of the performance gained by ignoring TypeScript. The plugin runs each typescript file through tsc before passing it…

--

--

Ben Force
Ben Force

Written by Ben Force

I am a 5x AWS certified senior full-stack developer. I write about cloud architecture, infrastructure as code, and automation.

No responses yet

Write a response