Registry / http-networking / typescript-debounce-decorator

typescript-debounce-decorator

JSON →
library0.0.18jsnpmunverified

typescript-debounce-decorator provides a lightweight and dependency-free TypeScript decorator for debouncing class methods. It enables developers to control the execution frequency of functions, preventing rapid, successive calls. The current stable version is 0.0.18, and while release cadence isn't explicitly stated, the version number suggests a mature, low-churn utility. Key differentiators include its minimal footprint (1KB after compression) and zero external dependencies, making it an ideal choice for projects prioritizing bundle size and avoiding dependency bloat. It supports both leading and trailing edge debouncing and offers a `cancel` function to abort pending debounced calls. A notable characteristic is that the return values of decorated methods are inherently discarded.

npm install typescript-debounce-decorator
INSTALL
IMPORT
SIG · TYPESCRIPT-DEBOUNC
T
typescript-debounce-decorator
http-networkingjavascriptv0.0.18
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

debounce
import { debounce } from 'typescript-debounce-decorator';
import debounce from 'typescript-debounce-decorator';
The `debounce` decorator is a named export, not a default export. Ensure you destructure it correctly.
cancel
import { cancel } from 'typescript-debounce-decorator';
const cancel = require('typescript-debounce-decorator').cancel;
The `cancel` function is also a named export for clearing pending debounced calls. CommonJS `require` syntax is not directly supported.
@debounce
class MyClass { @debounce(1000) myMethod() {} }
class MyClass { @debounce myMethod() {} } // Missing parenthesis, if no options are passed
When using the decorator without any arguments (e.g., just `@debounce`), the parentheses are still required, i.e., `@debounce()` or `@debounce` followed by an argument like `@debounce(1000)`.

This quickstart demonstrates how to apply the `@debounce` decorator to a class method, configure it for leading-edge execution, and use the `cancel` function to prevent pending debounced calls from firing.

import { debounce, cancel } from "typescript-debounce-decorator"; class MyService { private count: number = 0; constructor() { // Simulate user interaction setInterval(() => { console.log(`Calling increment by interval... current count: ${this.count}`); this.increment(); }, 200); // Schedule a cancellation after some time setTimeout(() => { console.log("Attempting to cancel pending increments..."); this.clearPending(); }, 1500); } @debounce(1000, { leading: true }) // Debounce for 1 second, fire on leading edge increment() { this.count++; console.log(`Incremented! New count: ${this.count}`); } clearPending() { cancel(this.increment); console.log("Cancellation command issued."); } } new MyService();
Debug
Known issues
breakingThe `leading` option for the `@debounce` decorator changed its default value from `true` to `false` in version 0.0.18.
fix
If your application relies on leading-edge debouncing behavior, you must explicitly set `{ leading: true }` in the decorator options: `@debounce(1000, { leading: true })`.
affects: >=0.0.18
gotchaMethods decorated with `@debounce` will have their return values 'eaten' (discarded). The decorator intercepts the method call and does not propagate the return value.
fix
Design your decorated methods to perform side effects rather than returning values, or refactor your logic to avoid debouncing methods whose return values are critical for subsequent operations.
affects: All versions
gotchaTypeScript decorators require specific compiler options to be enabled. Without them, you will encounter compilation errors.
fix
Ensure that `"experimentalDecorators": true` and `"emitDecoratorMetadata": true` are set under `"compilerOptions"` in your `tsconfig.json`.
affects: All versions (TypeScript usage)
Errors
Common errors & fixes
Decorators are not enabled. To enable them, set the 'experimentalDecorators' option to 'true' in your 'tsconfig.json' file.
The TypeScript compiler option `experimentalDecorators` is not enabled.
fix
Add `"experimentalDecorators": true` to the `compilerOptions` section of your `tsconfig.json`.
Cannot find name 'debounce'.
The `debounce` symbol has not been imported or the import path is incorrect.
fix
Ensure you have `import { debounce } from 'typescript-debounce-decorator';` at the top of your TypeScript file.
ReferenceError: Reflect is not defined OR Error: Reflect.metadata is not a function
The TypeScript compiler option `emitDecoratorMetadata` is enabled, but the `reflect-metadata` polyfill is not loaded at runtime.
fix
Install `reflect-metadata` (`npm install reflect-metadata`) and add `import 'reflect-metadata';` once at the entry point of your application (e.g., `main.ts` or `index.ts`).
Upgrade
Version history
0.0.18latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
39 hits · last 30 days
node
32
Meta
2
OpenAI (training)
1
Resources
typescript-debounce-decorator — npm install typescript-debounce-decorator · libregistry