0Pricing
TypeScript Academy · Lesson

Decorator Metadata

Attach and read metadata with the metadata API.

The Decorator Metadata API

Standardized decorators include a built-in metadata channel. The context object exposes a metadata object you can write to, and the class later carries it under the well-known Symbol.metadata key.

context.metadata

Every decorator context shares a single metadata object for the class being defined. Decorators attach data to it; it becomes the class metadata.

function tag(label: string) {
  return function (value: any, context: DecoratorContext) {
    context.metadata[context.name] = label;
  };
}

All lessons in this course

  1. Stage 3 Decorators Explained
  2. Decorator Metadata
  3. reflect-metadata and Design Types
  4. Building a Decorator Framework
← Back to TypeScript Academy