-
Notifications
You must be signed in to change notification settings - Fork 131
[CloudflareKVPlugin]: Incompatible types when passing in argument for kv #2104
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Coming back here. So the new snapshot is not working ? Are you sure you've cleaned up your node_modules and lockfile ? Because it really looks like multiple version of the |
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. |
Alright, so I'm at a very weird point now. I've narrowed down the type error to the I've made a simple test repository - https://github.com/AdiRishi/worker-graphql-typecheck All the types work just fine. Uncomment line 2 at index.ts import { YogaInitialContext, createSchema, createYoga } from "graphql-yoga"; And now the types break with the same error as seen above 😕 @EmrysMyrddin if you have any idea on what's going on let me know. I thought maybe the I'll keep investigating too 👍 |
Oh no 😒 I hate when TypeScript leads to this kind of problems... One thing you can check is I know we are doing some type override in Yoga which have side effects on import. |
@EmrysMyrddin thanks for the tip, that helped a lot in the investigation! Here's what I've found. In declare global {
interface ReadableStream<R = any> {
[Symbol.asyncIterator]: () => AsyncIterator<R>;
}
} This explains the error quite well. We can see that typescript is complaining about something to do with the declare interface KVNamespace<Key extends string = string> {
get(key: Key, type: "stream"): Promise<ReadableStream | null>;
get(
key: Key,
options?: KVNamespaceGetOptions<"stream">
): Promise<ReadableStream | null>;
} So, the error makes perfect sense now, graphql-yoga is changing the definition of export interface ReadableStream<R = any> {
readonly locked: boolean;
cancel(reason?: any): Promise<void>;
getReader(): ReadableStreamDefaultReader<R>;
getReader(options: ReadableStreamGetReaderOptions): ReadableStreamBYOBReader;
pipeThrough<T>(transform: ReadableWritablePair<T, R>, options?: StreamPipeOptions): ReadableStream<T>;
pipeTo(destination: WritableStream<R>, options?: StreamPipeOptions): Promise<void>;
tee(): [ReadableStream<R>, ReadableStream<R>];
values(options?: ReadableStreamValuesOptions): AsyncIterableIterator<R>;
[Symbol.asyncIterator](options?: ReadableStreamValuesOptions): AsyncIterableIterator<R>;
} Now, this error only happens because in typical workers projects, it is common to setup {
"compilerOptions": {
"types": [
"@cloudflare/workers-types"
]
}
} It's the default way a workers project is setup when you do If you were to remove the global definition of @EmrysMyrddin how should we proceed here? I think the PR made should be released anyway, since it makes sense that |
Let me check with the team why we do this black magic type declaration :-) |
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. |
Hey @AdiRishi! Did you have time to progress on this subject ? |
@EmrysMyrddin I did spend a little bit of time thinking about how I would fix the type. Just to explain the above, let's take a look at the docs for ReadableSteam async iteration. As the docs clearly say, you can use any readable stream object with an async for iteration loop. I'd love to take your advice on this, not really sure how to go about fixing all the locations which would break as a result of removing that global override. |
@enisdenjo Do you have an idea ? I'm not a TypeScript expert ^^' |
@EmrysMyrddin your bump on the docs PR got me to look into this again. I have a PR that does effectively remove the type override from the global namespace 🎉 |
Instead of a magic with type casts and so on, we can align Yoga's override with CloudFlare types by making the following change; declare global {
interface ReadableStream<R = any> {
- [Symbol.asyncIterator]: () => AsyncIterator<R>;
+ [Symbol.asyncIterator]: () => AsyncIterableIterator<R>;
}
} |
Also see my PR to simplify cache initialization for CloudFlare workers or any other dynamic cache initialization; |
Thanks for the feedback and work! I think #2238 solves it in a different way so we don't need to worry about the type conflicts. |
Describe the bug
When using the
createKvCache
export from@envelop/response-cache-cloudflare-kv
the passed in type ofKV
is rejected with this errorTo Reproduce Steps to reproduce the behavior:
Expected behavior
The types should be compatible.
Environment:
The text was updated successfully, but these errors were encountered: