Metadata and injection — TypeScript · Foundations

How NestJS knows what to pass to your constructor: the compiler records each decorated class's parameter types as metadata, and a container reads them to build every class with its dependencies. Build that container.

What you will learn

Read the theory for Metadata and injection

All TypeScript lessons

All Foundations courses

loading types…

What you'll learn

  • Define and read metadata on a class with reflect-metadata
  • Explain what emitDecoratorMetadata records in design:paramtypes, and why an interface appears there as Object
  • Build a dependency injection container that resolves constructor parameters recursively and shares one instance per class