Hey all, I've had an issue bugging me
Hey all, I've had an issue bugging me for a while, and I can't figure out how to fix it. Looking for help 🙏
I've been developing oss libraries to use with the cloudflare ecosystem, and I've always run into issues with KV typing.
Let me give an example. Here is a library that provides a kv adapter for epic-web/cachified - https://www.npmjs.com/package/cachified-adapter-cloudflare-kv
Here is my super simplified example setup with it
Tldr, I've never been able to get the KVNamespace type used inside the library to match the KVNamespace type used in the worker.
We see the following error
I know it's not a super simple ask, but I would greatly appreciate any help or tips.
3 Replies
Made a thread for this so as to not pollute the main chat. Happy to give any additional context needed
Hey @Adi
I think what you're running into is a different entrypoint being used in the library vs your code.
Looking at the source of
cachified-adapter-cloudflare-kv
it looks like it's using the oldest date:
And quite likely, you are (may I add, correctly, and as suggested by the docs) using 2023-07-01
, or some other dated entrypoint, corresponding to your worker compatibility date. These two definitions, while identical, create a conflict in TS that results in an error.
As for a solution, I usually patch all libraries importing from workers-types/declaring dependency with a ///
comment to synchronize the entrypoint they use, avoiding this error.Oooh I see! I didn't even consider that. I'll look down this angle.
Just curious, what's that
///
command you use to sync types?
So for someone developing a library. I assume the recommendation is to import the latest type within the library, and then add docs to explain how users can sync types using your ///
command?