Skip to content

InterceptorContext

@tsed/di

Usage

typescript
import { InterceptorContext } from "@tsed/di";

See /packages/di/src/common/interfaces/InterceptorContext.ts.

Overview

ts
interface InterceptorContext<Klass = Type, Opts = any> {
    target: Klass;
    propertyKey: string | symbol;
    args: any[];
    next: InterceptorNext;
    options?: Opts;
}

Description

Context object passed to interceptors during method execution.

Provides access to the target instance, method name, arguments, and control flow for intercepting and modifying method behavior.

Usage

typescript
import {Interceptor, InterceptorContext, InterceptorMethods} from "@tsed/di";

@Interceptor()
class LogInterceptor implements InterceptorMethods {
  intercept(context: InterceptorContext) {
    console.log("Before:", context.propertyKey);
    const result = context.next();
    console.log("After:", result);
    return result;
  }
}

target

ts
target: Klass;

propertyKey

ts
propertyKey: string | symbol;

args

ts
args: any[];

next

ts
next: InterceptorNext;

options

ts
options?: Opts;

Released under the MIT License.