diff --git a/lib/cache.module.ts b/lib/cache.module.ts index a525371..0d8ddf5 100644 --- a/lib/cache.module.ts +++ b/lib/cache.module.ts @@ -1,4 +1,5 @@ import { DynamicModule, Module } from '@nestjs/common'; +import type { Cache as CoreCache } from 'cache-manager' import { CACHE_MANAGER } from './cache.constants'; import { ConfigurableModuleClass } from './cache.module-definition'; import { createCacheManager } from './cache.providers'; @@ -7,6 +8,15 @@ import { CacheModuleOptions, } from './interfaces/cache-module.interface'; +/** + * This is just the same as the `Cache` interface from `cache-manager` but you can + * use this as a provider token as well. + */ +// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging +export abstract class Cache {} +// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging +export interface Cache extends CoreCache {} + /** * Module that provides Nest cache-manager. * @@ -15,8 +25,14 @@ import { * @publicApi */ @Module({ - providers: [createCacheManager()], - exports: [CACHE_MANAGER], + providers: [ + createCacheManager(), + { + provide: Cache, + useExisting: CACHE_MANAGER, + } + ], + exports: [CACHE_MANAGER, Cache], }) export class CacheModule extends ConfigurableModuleClass { /** diff --git a/tsconfig.json b/tsconfig.json index 519fca1..5b75837 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -2,7 +2,7 @@ "compilerOptions": { "module": "commonjs", "declaration": true, - "removeComments": true, + "removeComments": false, "noLib": false, "emitDecoratorMetadata": true, "esModuleInterop": true,