RFLCT: Bringing Runtime Type Metadata to TypeScript 7

2026年8月27日2 次浏览来源:Dev.to阅读原文

If you've built large-scale applications in TypeScript, chances are you've used a Dependency Injection (DI) container.

As the creator of InversifyJS, I've spent years thinking deeply about inversion of control, decoupling, and how to make enterprise patterns feel natural in TypeScript.

But for all those years, there has been a glaring elephant in the room: our heavy reliance on and .

These compiler flags have served us well, but they are exactly that—experimental.

They tie us to legacy decorator implementations, require specific compiler configurations, and often feel like a magic black box that doesn't perfectly align with modern build pipelines.

I've spent a lot of time recently thinking about how we could finally drop these flags entirely while keeping the developer experience pristine.

With the release of TypeScript 7, I'm thrilled to introduce the solution: 🪞 RFLCT.

What is RFLCT?

RFLCT is an ahead-of-time (AOT) reflect metadata injector for TypeScript

7.

It injects and directly at build time.

Zero decorators.

Zero .

It integrates seamlessly with virtually any build tool (Vite, Rollup, webpack, esbuild) via unplugin, or you can use the built-in CLI using the TypeScript 7 API for standalone projects.

Let's look at how it actually feels to write code with RFLCT.

The Magic: Before and After With RFLCT, you annotate the types you want to expose to your runtime metadata using a special wrapper type.

What you write: What RFLCT compiles it to: Notice how the interfaces are safely converted into global Symbols, and metadata is explicitly registered without a single decorator in sight.

Broader Than Just InversifyJS While my primary motivation for building RFLCT was to pave the way for the next generation of InversifyJS, this underlying primitive—a reliable, decorator-free way to emit runtime type metadata—unlocks so much more.

Because RFLCT standardizes how types are mapped to memory at build time, it has massive potential across the ecosystem: Custom DI Engines: Build your own lightweight inversion of control containers without metadata boilerplate.

Object Mapping & Hydration: Easily map database or API JSON results directly back into instantiated classes.

RPC Frameworks: Guarantee type-safe network boundaries by validating incoming arguments against compile-time metadata.

Runtime Validation: Perform deep runtime validation by reading exactly what types a constructor or method expects.

How It Works: The Three Transformations Under the hood, RFLCT performs three core transformations during your build step:

  1. — The Global Type Registry Every class, interface, and type alias in a file is registered in a process-wide on the global object.
    Interfaces & Types become universally unique Symbols (e.g., ).
    Classes map directly to their constructor.
  2. — Parameter Type Metadata Any parameter annotated with (or ) tells the compiler to produce a call: Constructors: , Methods: ,
  3. — Compile-Time Type Resolution Writing acts as a macro.
    It is replaced at compile time with the actual runtime identity of : compiles to compiles simply to Smart Symbol Qualification A massive headache with metadata in the past has been duplicate dependencies causing symbol collisions.
    Generated symbols use structured as .
    This prevents collisions, allows minor/patch versions to share symbols, and ensures that shared library types resolve to the exact same symbol reference in memory.
    Getting Started (Alpha Preview) ⚠️ **Note:* RFLCT is currently in its early stage and the npm module has not yet been published to the public registry.* For now, to try it out, you will need to download the source directly from GitHub and build it locally.
    1.
    Build from Source
    2.
    Project Setup Link the local package to your project: You'll need to import once at your application's entry point to polyfill the global APIs:
    3.
    Configure Your Build Tool Because RFLCT is built on top of , it drops straight into your existing pipeline.
    Vite: (Plugins for Rollup, esbuild, and webpack are als
分享
Baike.dev

baike.dev helps you discover great languages, frameworks, databases, DevOps and cloud-native tools.

Quick links

About

Contribute

Found a great developer tool? Share it with the community.

Submit a tool
© 2026 baike.dev Developer EncyclopediaUpdated daily · Discover great developer tools