I've developed an interface specifically designed for types capable of self-converting to IDBKey
:
interface IDBValidKeyConvertible<TConvertedDBValidKey extends IDBValidKey> {
convertToIDBValidKey: () => TConvertedDBValidKey;
}
My goal now is to create a class that can accept a type that is either IDBKey
or IDBValidKeyConvertible
:
class InMemoryIndexedKeyValueStore<TKey extends IDBValidKey | IDBValidKeyConvertible<UKey>, TValue> {
public constructor(public readonly storeName: string) { }
private getDbKeyFromKey(key: TKey): TKey | UKey {
return isIDBValidKeyConvertible(key) ? key.convertToIDBValidKey() : key;
}
...
}
However, I'm encountering an issue where the TypeScript compiler throws an error regarding 'UKey' in the class declaration:
Cannot find name 'UKey'
Could this be related to the TypeScript limitation discussed in this issue, where generics might not support "higher kinded types?" Or could there be another mistake in my approach?
Any insights on this would be greatly appreciated!