Skip to content

Bind

reference
1 min readUpdated

Kind: Function

Source: packages/common/decorators/core/bind.decorator.ts

Part of: Common

Decorator that binds parameter decorators to the method that follows.

Useful when the language doesn't provide a 'Parameter Decorator' feature (i.e., vanilla JavaScript).

Bind creates a method decorator that attaches the supplied decorators to the method it decorates. It is primarily used to apply parameter-oriented decorators in environments such as vanilla JavaScript, where parameter decorator syntax is not available.

Signature

ts
function Bind(decorators: any[]): MethodDecorator

Parameters

NameType
decoratorsany[]

Returns: MethodDecorator

Diagram

mermaid
graph LR
  A[Bind decorator factories] --> B[@Bind(...decorators)]
  B --> C[Following method]
  C --> D[Apply supplied decorators]
  D --> E[Method metadata / runtime behavior]

Usage

ts
import { Bind, Controller, Get, Param } from '@nestjs/common';

@Controller('users')
export class UsersController {
  @Get(':id')
  @Bind(Param('id'))
  findOne(id: string) {
    return { id };
  }
}

AI Coding Instructions

  • Use Bind when parameter decorator syntax cannot be used directly, especially in JavaScript-based controllers.
  • Pass decorator factories, such as Param('id'), Body(), or custom parameter decorators, rather than raw values.
  • Place @Bind(...) on the method that should receive the decorator metadata.
  • Keep the bound decorators aligned with the method’s expected arguments and request-handling behavior.

Used by

1 reference from 1 file. Each is a place in this repository where the symbol is actually used — go read one rather than trusting an example.

Imported by (1)

  • CatsControllersample/09-babel-example/src/cats/cats.controller.js:12

Was this page helpful?

Download as PDF
Bind — NestJS head-to-head