ipfs / js-ipfs

IPFS implementation in JavaScript
https://js.ipfs.tech
Other
7.43k stars 1.25k forks source link

`IPFSService` is not assignable to the `MultiService` type parameter. #4089

Closed bgins closed 1 year ago

bgins commented 2 years ago

Severity: High. Type error prevents compilation with TypeScript.

Description:

When instantiating a Server with ipfs-message-port-server, the IPFSService is not assignable to the MultiService type parameter. I expect the a server can be instantiated with a service configured with an IPFS instance created by ipfs or ipfs-core.

Steps to reproduce the error:

In brief:

import { create } from "ipfs-core" // or "ipfs"
import { Server, IPFSService } from "ipfs-message-port-server"

const ipfs = await create()
const service = new IPFSService(ipfs)
const server = new Server(service)

Minimal reproduction: https://github.com/bgins/ipfs-message-port-server-type-error

Error message:

$ tsc
src/worker.ts:7:27 - error TS2345: Argument of type 'IPFSService' is not assignable to parameter of type 
'MultiService<{ dag: { ipfs: ...; put: ...; get: ...; resolve: ...; }; core: { ipfs: ...; addAll: ...; add: ...; 
cat: ...; ls: ...; }; files: { ipfs: ...; stat: ...; }; block: { ipfs: ...; get: ...; put: ...; rm: ...; stat: ...; }; }>'.
  The types of 'dag.ipfs' are incompatible between these types.
    Type 'IPFS<any>' is not assignable to type 'never'.

7 const server = new Server(service)
                            ~~~~~~~
welcome[bot] commented 2 years ago

Thank you for submitting your first issue to this repository! A maintainer will be here shortly to triage and review. In the meantime, please double-check that you have provided all the necessary information to make this process easy! Any information that can help save additional round trips is useful! We currently aim to give initial feedback within two business days. If this does not happen, feel free to leave a comment. Please keep an eye on how this issue will be labeled, as labels give an overview of priorities, assignments and additional actions requested by the maintainers:

Finally, remember to use https://discuss.ipfs.io if you just need general support.

BigLep commented 2 years ago

@bgins: thanks for reporting. js-ipfs maintainers are tied up currently. Is this something you could potentially take on? Contributions welcome.

bgins commented 2 years ago

Hey @BigLep! Thanks for the reply. I'm also tied up at the moment, but I think it should be possible to work around this issue with a bit of type casting:

const service = new IPFSService(ipfs) as unknown as MultiService<IPFSService>

If that doesn't work out, I'll revisit.

achingbrain commented 1 year ago

js-IPFS is in the process of being deprecated, the replacement is Helia - please see the State of IPFS in JS post for a bit of background and the migration guide for how to port your app over.

There's no direct replacement for the message port server yet, but something similar should be fairly easy to create.