Importing @keyv/redis causes TypeScript error: Cannot find name 'Value'.
See original GitHub issueDescribe the bug Simply loading @keyv/redis in a TS project causes transpilation error:
> tsc
node_modules/@keyv/redis/src/index.d.ts:6:63 - error TS2304: Cannot find name 'Value'.
6 declare class KeyvRedis extends EventEmitter implements Store<Value> {
~~~~~
node_modules/@keyv/redis/src/index.d.ts:13:28 - error TS2304: Cannot find name 'Value'.
13 get(key: string): Promise<Value>;
~~~~~
node_modules/@keyv/redis/src/index.d.ts:16:22 - error TS2304: Cannot find name 'Value'.
16 ): Array<StoredData<Value>> | Promise<Array<StoredData<Value>>> | undefined;
~~~~~
node_modules/@keyv/redis/src/index.d.ts:16:57 - error TS2304: Cannot find name 'Value'.
16 ): Array<StoredData<Value>> | Promise<Array<StoredData<Value>>> | undefined;
~~~~~
node_modules/@keyv/redis/src/index.d.ts:17:26 - error TS2304: Cannot find name 'Value'.
17 set(key: string, value: Value, ttl?: number): any;
~~~~~
Found 5 errors in the same file, starting at: node_modules/@keyv/redis/src/index.d.ts:6
How To Reproduce (best to provide workable code or tests!) Im upgrading from
- “@keyv/redis”: “2.3.7”,
- “keyv”: “4.3.2” but experience the above error when building with TypeScript 4.8.4
Upgrading to
- “@keyv/redis”: “2.5.1”,
- “keyv”: “4.5.0”
the following examples causes the above compilation errors.
RedisCache.ts
- Note that this is a dumbed down snippet from my project.
import Keyv from 'keyv';
import KeyvRedis from '@keyv/redis';
import { ICache } from './ICache';
export type RedisCacheOptions = {
namespace: string,
ttl: number
};
export class RedisCache<T> implements ICache<T> {
private readonly keyv: Keyv;
constructor(options: RedisCacheOptions) {
this.keyv = new Keyv({
namespace: options.namespace,
ttl: options.ttl
});
}
public async clear(): Promise<void> {
return this.keyv.clear();
}
public async delete(key: string): Promise<void> {
await this.keyv.delete(key);
return undefined;
}
public async get(key: string): Promise<any | undefined> {
return this.keyv.get(key);
}
public async set(key: string, value: any, ttl?: number): Promise<void> {
await this.keyv.set(key, value, ttl);
return undefined;
}
}
Looking at the content of https://github.com/jaredwray/keyv/blob/f060943bd21b4de17b5b7be956debad86d6633d1/packages/redis/src/index.d.ts I don’t see where Value
should come from. Also, none of the other apaters’ typedefinitions forward or define this themselves. It’s only defined as any
in the typedefinitions of keyv
itself.
Should the adapters themselves not let this be customisable? Something like
declare class KeyvRedis<Value = any> extends EventEmitter implements Store<Value> {}
Issue Analytics
- State:
- Created a year ago
- Reactions:1
- Comments:5 (3 by maintainers)
Top Results From Across the Web
TypeScript getting error TS2304: cannot find name ' require'
For example, import express from "express"; is now telling me that I need to try installing @types/express or add a .d.ts file for...
Read more >[TypeScript] "error TS2304: Cannot find name 'moment'" when ...
Unfortunately, my project does not use a bundler or module system, so I'm stuck with "module": "none" for now.
Read more >@keyv/redis - npm
Start using @keyv/redis in your project by running `npm i @keyv/redis`. ... TypeScript icon, indicating that this package has built-in type ...
Read more >cannot find module 'process' or its corresponding type ...
If you just use the variable without an import statement, you get the error: Cannot find name 'process'. Do you need to install...
Read more >TypeScript error TS2304 cannot find name require - Edureka
The error that I'm getting is the "TS2304: Cannot find name 'require' " when I attempt to transpile a simple TypeScript Node.js page....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
It looks like this pull request will fix this issue and we will be merging today and releasing in the next couple days. https://github.com/jaredwray/keyv/pull/513
Let us know if you can validate it. Closing this issue at this time since it is being merged.
@rasmuslp - we are looking into this and most likely will have a fix soon.