In TypeScript, `Level` is not assignable to `AbstractLevel<Buffer, any, any>` when constructing `ManyLevelHost`
Argument of type 'Level<string, string>' is not assignable to parameter of type 'AbstractLevel<Buffer, any, any>' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties.
Types of property 'batch' are incompatible.
Type '{ (operations: (AbstractBatchPutOperation<Level<string, string>, string, string> | AbstractBatchDelOperation<Level<string, string>, string>)[]): Promise<...>; (operations: (AbstractBatchPutOperation<...> | AbstractBatchDelOperation<...>)[], callback: NodeCallback<...>): void; <K = string, V = string>(operations: (Ab...' is not assignable to type '{ (operations: AbstractBatchOperation<AbstractLevel<Buffer, any, any>, any, any>[]): Promise<void>; (operations: AbstractBatchOperation<AbstractLevel<Buffer, any, any>, any, any>[], callback: NodeCallback<...>): void; <K = any, V = any>(operations: AbstractBatchOperation<...>[], options: AbstractBatchOptions<...>): ...'.
Types of parameters 'operations' and 'operations' are incompatible.
Type 'AbstractBatchOperation<AbstractLevel<Buffer, any, any>, any, any>[]' is not assignable to type '(AbstractBatchPutOperation<Level<string, string>, string, string> | AbstractBatchDelOperation<Level<string, string>, string>)[]'.
Type 'AbstractBatchOperation<AbstractLevel<Buffer, any, any>, any, any>' is not assignable to type 'AbstractBatchPutOperation<Level<string, string>, string, string> | AbstractBatchDelOperation<Level<string, string>, string>'.
Type 'AbstractBatchPutOperation<AbstractLevel<Buffer, any, any>, any, any>' is not assignable to type 'AbstractBatchPutOperation<Level<string, string>, string, string> | AbstractBatchDelOperation<Level<string, string>, string>'.
Type 'AbstractBatchPutOperation<AbstractLevel<Buffer, any, any>, any, any>' is not assignable to type 'AbstractBatchPutOperation<Level<string, string>, string, string>'.
Types of property 'sublevel' are incompatible.
Type 'AbstractSublevel<AbstractLevel<Buffer, any, any>, any, any, any> | undefined' is not assignable to type 'AbstractSublevel<Level<string, string>, any, any, any> | undefined'.
Type 'AbstractSublevel<AbstractLevel<Buffer, any, any>, any, any, any>' is not assignable to type 'AbstractSublevel<Level<string, string>, any, any, any>' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties.
Types of property 'db' are incompatible.
Type 'AbstractLevel<Buffer, any, any>' is not assignable to type 'Level<string, string>' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties.ts(2379)
What code results in this error?
Just the simple instantiation.
const db = new Level(name)
const host = new ManyLevelHost(db)
The tsconfig.json used was from the @tsconfig/strictest package.
We can change the AbstractLevel<Buffer, any, any> to AbstractLevel<any, any, any> here:
https://github.com/Level/many-level/blob/a56d72df52c3f9d301a0885705c5dc223576ef31/index.d.ts#L74
My intent was probably to enforce that the given database supports Buffer, but that's not really a job for TypeScript and it does not actually affect the ManyLevelHost API (which is just a constructor and one method).
Could you try this out and send a PR if it works?
That does seem to work, but if it's not desired to be typed that way, the documentation could mention to do new Level<Buffer> or new Level<Buffer, /* key, value types */> as a blurb f for TypeScript usage.
That does seem to work
Great!
if it's not desired to be typed that way, the documentation could mention to do
new Level<Buffer>ornew Level<Buffer, /* key, value types */>as a blurb f for TypeScript usage.
Nah, the current type does not benefit users. Let's change it to any.