envelop: [CloudflareKVPlugin]: Incompatible types when passing in argument for kv
Describe the bug
const kvCache = createKvCache({
KV: env.GRAPHQL_RESPONSE_CACHE,
ctx,
keyPrefix: 'graphql', // optional
cacheReadTTL: 1000 * 60 * 60 * 4, // 4 hours
});
When using the createKvCache export from @envelop/response-cache-cloudflare-kv the passed in type of KV is rejected with this error
src/index.ts:29:9 - error TS2322: Type 'KVNamespace<string>' is not assignable to type 'import("/Users/arishi/personal/sukrit-ecosystem-turborepo/node_modules/.pnpm/@cloudflare+workers-types@4.20231121.0/node_modules/@cloudflare/workers-types/index").KVNamespace<string>'.
Types of property 'get' are incompatible.
Type '{ (key: string, options?: Partial<KVNamespaceGetOptions<undefined>> | undefined): Promise<string | null>; (key: string, type: "text"): Promise<...>; <ExpectedValue = unknown>(key: string, type: "json"): Promise<...>; (key: string, type: "arrayBuffer"): Promise<...>; (key: string, type: "stream"): Promise<...>; (key:...' is not assignable to type '{ (key: string, options?: Partial<import("/Users/arishi/personal/sukrit-ecosystem-turborepo/node_modules/.pnpm/@cloudflare+workers-types@4.20231121.0/node_modules/@cloudflare/workers-types/index").KVNamespaceGetOptions<undefined>> | undefined): Promise<...>; (key: string, type: "text"): Promise<...>; <ExpectedValue ...'.
Types of parameters 'options' and 'type' are incompatible.
Type '"stream"' has no properties in common with type 'Partial<KVNamespaceGetOptions<undefined>>'.
29 KV: env.GRAPHQL_RESPONSE_CACHE,
~~
../../node_modules/.pnpm/@envelop+response-cache-cloudflare-kv@0.2.0_@envelop+response-cache@6.1.1_graphql@16.8.1/node_modules/@envelop/response-cache-cloudflare-kv/typings/index.d.ts:7:5
7 KV: KVNamespace;
~~
The expected type comes from property 'KV' which is declared here on type 'KvCacheConfig'
Found 1 error in src/index.ts:29
To Reproduce Steps to reproduce the behavior:
Expected behavior
The types should be compatible.
Environment:
- OS: MacOS
- NodeJS: 18.x
- “@envelop/response-cache”: “^6.1.1”,
- “@envelop/response-cache-cloudflare-kv”: “0.2.0”,
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 15 (9 by maintainers)
After some discutions, we definitely should not do this.
You can make a PR to remove this if you want 😃
Alright, I’ll give it a shot 😃
Edit: I will likely be busy with personal work until the 18th of December. If I find time in between I may be able to finish this. But if not, expect some progress after the 18th.
Let me check with the team why we do this black magic type declaration 😃
Yeah I’m definitely inclined to agree with you here. I’m just going to make a clean test repo and see if this same issue exists, if not, I’ll chalk it up to something weird with my setup.