when using it directly it all works but when using it via, let’s say Fastify plugin I cannot type the interface. any suggestions?
I don’t know if IPFS has started using TypeScript yet or not, but converting any large project to TS is almost guaranteed to uncover many unknown bugs, so I hope they do it. Pure JS is like working in the stone ages, at least for large projects. A total inability to detect typos at compile time is not a small thing, and that’s the case with pure JS. But I know TypeSafety is a highly contentious topic, so merely stating an opinion is frequently considered offensive. lol.
Anyway here’s a link that might help:
Pure JS is like working in the stone ages, at least for large projects.
I agree with that. The link you sent I don’t think will help because of the way they wrote the library.
Anyways I think I might start slowly start building the lib in TS as a replacement for that one, one method by one, in the order I need them.
I really just wanted to help point you in the right direction, only in case you didn’t know those things (d.ts
files, etc). I’m sure the IPFS team knows they can supply d.ts typings for IPFS even without converting any of their code to TS, and I bet there might be some typings out there. I guess you googled it already.
I really just wanted to help point you in the right direction,
I know and I appreciate that
Sure I know of *.d.ts
files. i tried with export as namespace ipfsClient
which was imported from the lib but it didn’t work.
The thing is that when you init the client then use it, it works. If you try to export it the TS will complain and if you want to use it as a plugin in let’s say express using the expressApp.set(ipfsClient)
and type it, it will not work due to the types are forwarded via comments.
You can see what I am talking about here https://github.com/ipfs/js-ipfs/blob/master/packages/ipfs-http-client/src/index.js and here https://github.com/ipfs/js-ipfs/blob/master/packages/ipfs-http-client/src/cat.js
here is the start src/types/ipfs-http-client.d/index.d.ts · main · Kelp Digital / IPFS files management · GitLab
What I’m doing for my API layer is that I just talk to IPFS via the HTTP API from Java (for me using the GO-IPFS docker image), so I’m just posting JSON and receiving back JSON. That way I don’t know or care about any of the actual IPFS code (neither JS nor GO).
However, it seems likely IPFS is going to eventually supply d.ts files (all JS is moving to TS) so if it were me I wouldn’t bother replicating that work. I’d just create interfaces to “wrap” my calls to IPFS in TS, and then because of my own wrapping I’d get the safety, which is the main goal.