js-ipfs icon indicating copy to clipboard operation
js-ipfs copied to clipboard

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

Open bgins opened this issue 3 years ago • 3 comments

  • Version:

    • ipfs at v0.62.2
    • ipfs-core at v0.14.2
    • ipfs-message-port-server at v0.11.2
    • tsc at v4.6.3
  • Platform: The bug is with the TypeScript types, so the most relevant platform is tsc at v4.6.3

  • Subsystem: ipfs-message-port-server

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)
                            ~~~~~~~

bgins avatar Apr 26 '22 18:04 bgins

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:

  • "Priority" labels will show how urgent this is for the team.
  • "Status" labels will show if this is ready to be worked on, blocked, or in progress.
  • "Need" labels will indicate if additional input or analysis is required.

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

welcome[bot] avatar Apr 26 '22 18:04 welcome[bot]

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

BigLep avatar May 06 '22 14:05 BigLep

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.

bgins avatar May 06 '22 17:05 bgins

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.

achingbrain avatar May 22 '23 14:05 achingbrain