09 / 11

What is the shorthand provider syntax in NestJS and what does it expand to?

When you write a class name directly in the providers array, NestJS expands it to the full useClass form where the class is used as both the token and the implementation. This works because TypeScript emits metadata for class types so the container knows how to instantiate it.

Shorthand vs full provider form
When shorthand works and when it does not:
  1. 1

    Shorthand works only when the class itself is the token — the most common case.

  2. 2

    Use full form when providing an interface token, string token, or swapping implementation.

  3. 3

    Use full form when using useValue, useFactory, or useExisting.

  4. 4

    Shorthand is just syntactic sugar — both forms produce identical DI behavior.