Open sumbricht opened 2 months ago
I'm also getting this issue but only after upgrading typescript to 5.4.5 from 5.2.2: -
X [ERROR] TS2344: Type 'IndexNames<DBTypes, StoreName>' does not satisfy the constraint 'string'. Type 'string | number' is not assignable to type 'string'. Type 'number' is not assignable to type 'string'. [plugin angular-compiler]
node_modules/idb/build/entry.d.ts:359:44:
359 │ ...y indexNames: TypedDOMStringList<IndexNames<DBTypes, StoreName>>;
+1
+1
"@tempfix/idb": "^8.0.3" solves the problem for now by implementing the fix suggested above.
+1
When compiling any project that relies on the idb library, I'm getting the following TypeScript error:
Error: node_modules/idb/build/entry.d.ts:359:45 - error TS2344: Type 'IndexNames<DBTypes, StoreName>' does not satisfy the constraint 'string'
Looking at entry.d.ts, this error is actually correct. The error occurs in the property definition of
indexNames
:TypesDOMStringList<T extends string>
expectsIndexedNames
to be of assignable tostring
but this turns out to bestring | number
due to the wayIndexedNames
is defined. The expressionkeyof DBTypes[StoreName]['indexes']
is unfortunatelystring | number
even if it should intuitively bestring
only.To verify this, let's look at a simplified example:
To solve the problem, I propose changing the type
IndexNames
fromexport declare type IndexNames<DBTypes extends DBSchema | unknown, StoreName extends StoreNames<DBTypes>> = DBTypes extends DBSchema ? keyof DBTypes[StoreName]['indexes'] : string;
toexport declare type IndexNames<DBTypes extends DBSchema | unknown, StoreName extends StoreNames<DBTypes>> = DBTypes extends DBSchema ? keyof DBTypes[StoreName]['indexes'] & string : string;
As it's a very quick fix it may be easier for you to just do it; if you'd like a PR, just let me know :-).
Thanks a lot for your help and the great work on this library!