-
Notifications
You must be signed in to change notification settings - Fork 113
Description
When using NDKCacheAdapterDexie with TypeScript in a project that conditionally uses the cache adapter based on environment, there's a type compatibility issue requiring explicit casting:
// This doesn't work without casting:
const cacheAdapter: NDKCacheAdapter | undefined = isBrowser
? new NDKCacheAdapterDexie({ dbName: 'nostr-cache' })
: undefined
The error indicates that NDKCacheAdapterDexie is not assignable to type NDKCacheAdapter. To fix it, we need an explicit cast:
const cacheAdapter: NDKCacheAdapter | undefined = isBrowser
? new NDKCacheAdapterDexie({ dbName: 'nostr-cache' }) as unknown as NDKCacheAdapter
: undefined
Error Details
Type 'NDKCacheAdapterDexie | undefined' is not assignable to type 'NDKCacheAdapter | undefined'.
Type 'NDKCacheAdapterDexie' is not assignable to type 'NDKCacheAdapter'.
Types of property 'query' are incompatible.
Type '(subscription: NDKSubscription) => Promise<NDKEvent[]>' is not assignable to type '(subscription: NDKSubscription) => NDKEvent[] | Promise<NDKEvent[]>'.
Types of parameters 'subscription' and 'subscription' are incompatible.
Type 'import("/.../node_modules/@nostr-dev-kit/ndk/dist/index").NDKSubscription' is not assignable to type 'import("/.../node_modules/@nostr-dev-kit/ndk-cache-dexie/node_modules/@nostr-dev-kit/ndk/dist/index").NDKSubscription'.
Types of property 'filters' are incompatible.
...
Property 'Video' is missing in type 'import("/.../node_modules/@nostr-dev-kit/ndk-cache-dexie/node_modules/@nostr-dev-kit/ndk/dist/index").NDKKind'.
The root cause appears to be that ndk-cache-dexie is using a different version of the NDK package internally than the one in our project, leading to incompatible type definitions for NDKKind (missing the Video property in the nested dependency).
Expected Behavior
Since NDKCacheAdapterDexie implements the NDKCacheAdapter interface, it should be directly assignable without explicit casting.
Environment
NDK: 2.13.0
NDK-cache-dexie: 2.5.15
TypeScript with Bun + React