The `typescript-retry-decorator` library provides a simple, zero-dependency decorator for adding retry logic to TypeScript functions, inspired by Spring-Retry. It supports both synchronous and asynchronous (Promise-returning) functions, making it suitable for Node.js and modern browser environments. The current stable version is 2.5.4, with releases occurring periodically, often addressing compatibility with newer TypeScript features or Node.js module systems, as seen in recent 2.5.x patches. Its key differentiators include its lightweight nature (no external dependencies), comprehensive test coverage, and support for both legacy and TypeScript 5+ standard decorators, offering various backoff policies (fixed, exponential with jitter) and custom error handling for retry conditions.
npm install typescript-retry-decoratorVerified import paths — ran on the pinned version, not inferred.
Demonstrates applying the `@Retry` decorator to an asynchronous method, configured with exponential backoff and custom retry conditions for transient errors.
Ensure your project is configured for proper ESM consumption (e.g., `"type": "module"` in `package.json`, using explicit `.js` extensions where needed for Node.js ESM) or explicitly target the CJS build if your tooling requires it (though direct subpath imports are not officially supported). Update to the latest patch version (>=2.5.4) for best compatibility.
For legacy decorators, ensure `"experimentalDecorators": true` and `"emitDecoratorMetadata": true` are set in `tsconfig.json`. For TS5+ standard decorators, no special `tsconfig.json` flags are needed, but ensure your TypeScript version is 5.0 or higher.
Set `useOriginalError: true` in the `@Retry` decorator options if you need the original error to propagate on final failure instead of `MaxAttemptsError`.
Review code interacting with the retry decorator, especially error handlers and decorator options, to ensure null and undefined values are handled explicitly, adhering to stricter TypeScript rules.
If using Node.js and an specific CommonJS setup, try updating Node.js, your bundler, or TypeScript configuration. For most modern setups, switch to `import { Retry } from 'typescript-retry-decorator';`. Ensure `package.json` for your project either has `"type": "module"` (for ESM) or correctly handles CJS interop if `"type": "commonjs"`.Ensure `"experimentalDecorators": true` and `"emitDecoratorMetadata": true` are present in your `tsconfig.json` if using TypeScript versions prior to 5.0 or opting into legacy decorators. If using TS 5.0+, ensure no conflicting experimental decorator flags are set and your TypeScript version is correctly configured.
Ensure the `value` option is an array containing constructor functions of `Error` types, like `value: [Error, CustomTransientError]`.
No dependency data recorded yet.