-
Notifications
You must be signed in to change notification settings - Fork 765
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
CheckpointDB
's implementation of DB
makes types too narrow
#2393
Comments
Would you have some example code that is causing issues? I have a database implementation in my project that has more methods implemented than the If your issue is that |
@faustbrian thanks for the response! You are correct that we are expecting the import { DB, Trie } from "@ethereumjs/trie";
import { Level } from "level";
const DB_OPTS = {};
class MyDB extends Level<Buffer, Buffer> implements DB {
constructor(location: string) {
super(location, DB_OPTS);
}
copy() {
return new MyDB(this.location);
}
}
class MyTrie extends Trie {
constructor(db: MyDB, root: Buffer) {
super({ db, root, useRootPersistence: true, useKeyHashing: true });
}
}
const myDB = new MyDB("");
const myTrie = new MyTrie(myDB, null);
myDB.iterator(); // all good
myTrie.database().db.iterator; // type error Previously, we could use the database from the Sure, we could add some |
That sounds like a leaky abstraction (which is always an awful idea) and the more sane solution would be to bind your database instance to a container or kind of shared access object in your application rather than expecting third-party libraries to mirror your application-specific interfaces and logic but I'm not a maintainer so not up to me to decide those things. Also, the |
What's the state of this discussion? 🙂 @MicaiahReid is it an option to do the architectural changes @faustbrian recommended? Any other suggestions or alternative ways to go? Happy to hear additional comments and weightings! 🤓 😀 |
Hi @holgerd77, @faustbrian, We have managed to make the changes internally to get the types here to work. Things still would be a little cleaner if the Thanks for the responses! |
I believe this issue will be obsolete with the v7 releases. Feel free to reopen if I'm mistaken |
@acolytec3 I am not so sure if this issue is really resolved in v7, I would not know how? I think we should nevertheless close here though, this has been stale long enough, seems not pressing enough to be picked up by someone. |
Because
CheckpointDB implements DB
, the types for the database supplied by the user are restricted to only those defined inDB
(i.e.get
,put
,del
,batch
,copy
). This forces the user to restrict the properties of their database instances, or to haveas AnotherDatabaseType
type assertions in their code.Ideally, the
DB
interface should be used to enforce that whatever database is used by the user has, at a minimum, all of the properties defined byDB
, but that the other properties of the user's database are passed through the type system so that they are available for consumption.(I have a PR incoming that will attempt to implement this)
The text was updated successfully, but these errors were encountered: