Skip to content

ParamMetadata

reference
1 min readUpdated

Kind: Interface

Source: packages/core/helpers/interfaces/params-metadata.interface.ts

Part of: Core

ParamMetadata describes metadata for a single parameter in a handler, resolver, or decorated method. It stores the parameter's positional index and associated data, allowing the framework to resolve and inject the correct value at runtime.

Properties

PropertyType
indexnumber
dataParamData

Diagram

mermaid
graph LR
  Handler[Handler Method] --> Params[Parameter List]
  Params --> Metadata[ParamMetadata]
  Metadata --> Index[index: number]
  Metadata --> Data[data: ParamData]
  Metadata --> Resolver[Parameter Resolver]

Usage

ts
import type { ParamMetadata } from './helpers/interfaces/params-metadata.interface';

const userIdParam: ParamMetadata = {
  index: 0,
  data: {
    name: 'userId',
    type: 'param',
  },
};

function resolveParameter(metadata: ParamMetadata, request: Request) {
  if (metadata.data.type === 'param') {
    return request.params[metadata.data.name];
  }

  return undefined;
}

const userId = resolveParameter(userIdParam, request);

AI Coding Instructions

  • Keep index aligned with the parameter's zero-based position in the target method signature.
  • Use the appropriate ParamData shape when creating metadata; avoid replacing it with untyped objects.
  • Preserve parameter metadata ordering when collecting metadata for a method or resolver.
  • Use ParamMetadata with the parameter-resolution pipeline rather than reading request or context values directly in framework internals.

Was this page helpful?

Download as PDF
ParamMetadata — NestJS head-to-head