Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

Export IPFS instance type #3439

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions packages/ipfs-core/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,19 @@ const multicodec = require('multicodec')
const multihashing = require('multihashing-async')
const multihash = multihashing.multihash
const CID = require('cids')
const IPFS = require('./components')
const { create } = require('./components')

/**
* Export IPFS instance type
*
* This will result in `export default import("./components")`
* in the generated `d.ts` file
*
* @typedef {import('./components')} default
Xmader marked this conversation as resolved.
Show resolved Hide resolved
*/

module.exports = {
create: IPFS.create,
create,
crypto,
isIPFS,
CID,
Expand Down
9 changes: 9 additions & 0 deletions packages/ipfs/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,13 @@

const IPFS = require('ipfs-core')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be simpler to do this instead

Suggested change
const IPFS = require('ipfs-core')
/**
* @typedef {import(‘ipfs-core/src/components’)} IPFS
*/
module.exports = require('ipfs-core')

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does not work because @typedef {import('ipfs-core/src/components')} IPFS will not overlap onto the exports

Generated d.ts file:

declare const _exports: typeof import('ipfs-core/src')
export = _exports;
export type IPFS = import('ipfs-core/src/components');

We can't use

import type IPFS from "ipfs"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Xmader I realize that, but point I was trying to make is, having export type IPFS is just simpler and in the nutshell will give us:

import { IPFS, create } from "ipfs"

Furthermore I expect that as we adopt approach proposed in #3413 we might end up with IPFS interface that in the future could be exported in place of IPFS type.

That said, it's an @achingbrain call


/**
* Export IPFS instance type
*
* This will overlap onto the default export
* in the generated `d.ts` file
*
* @typedef {import('ipfs-core').default} IPFS
*/

module.exports = IPFS