ipfs-examples / helia-examples

Ready-to-run Helia examples for Node.js and the browser
79 stars 62 forks source link

Typescript Error: Both `MemoryBlockstore` & `MemoryDatastore` have mismatched types when being passed to `createHelia()`` #54

Open AustinFoss opened 1 year ago

AustinFoss commented 1 year ago

When attempting to integrate the 301.js example from the Helia 101 example repo with a Nuxt3 project I ran into problems using Helia in a TypeScript context.

Lines 50 & 51 in the return statement of createHelia both datastore & blockstore are throwing similar but different errors.

creatHelia(init?: HeliaInit | undefined) is expecting the "Datastore" & "BlockStore" elements of the HeliaInit interface to have matching interfaces to the ones imported from interface-datastore & interface-blockstore

However in the 301 example the two value assigned to those elements are imported from datastore-core & blockstore-core as MemoryDatastore & MemoryBlockstore respectively.

Datastore error:

Type 'MemoryDatastore' is not assignable to type 'Datastore<{}, {}, {}, {}, {}, {}, {}, {}, {}, {}>'. The types of 'batch().put' are incompatible between these types.

Blockstore error:

Property 'getAll' is missing in type 'MemoryBlockstore' but required in type 'Blockstore<{}, {}, {}, {}, {}, {}, {}, {}>'.

I'm aware that Nuxt3 is not currently among the existing examples, and non of the existing ones show Typescript compatibility so I'll probably pause my experiment here for now.

Hopefully this provides enough documentation about the problem for yourselves to replicate the issue.

AustinFoss commented 1 year ago

I've gone ahead and implemented a quick work around for myself that fixes the Typescript problem, still can't get Nuxt3 working as it complains about something else (I think it's vite related because the error mentions os.networkinterfaces so something to do with bundling maybe).

https://github.com/ipfs/helia/compare/main...AustinFoss:helia:heliainit-interface-fix

I haven't created a pull request or anything for it yet because this feels hacky but hope this helps.