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

Fixes typo in pull request 3607 #3918

Closed

Conversation

dancingfrog
Copy link

See comment on #3607 (comment)

Copy link
Member

@lidel lidel left a comment

Choose a reason for hiding this comment

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

@dancingfrog not sure if this change is needed, need more info.

  1. How are you using js-ipfs? In browser? Node? Electron?
  2. How are you building it?

@dancingfrog
Copy link
Author

@lidel

@dancingfrog not sure if this change is needed...

I'm guessing you did not follow the link to the comment. Otherwise you are saying that this typo on line 75 of packages/ipfs-http-gateway/src/index.js is not a problem

const gatewayAddrs = addresses?.Gateway || []

@lidel
Copy link
Member

lidel commented Oct 29, 2021

Hm.. iiuc ?. is not a typo, it is Optional Chaining and is used in other places as well:

Click to see use of ?. in js-ipfs codebase
./packages/ipfs-http-gateway/src/index.js
75:    const gatewayAddrs = addresses?.Gateway || []

./packages/ipfs/test/interface-http-js.js
6:const isFirefox = globalThis.navigator?.userAgent?.toLowerCase().includes('firefox')

./packages/ipfs/test/interface-http-go.js
6:const isFirefox = globalThis.navigator?.userAgent?.toLowerCase().includes('firefox')

./packages/ipfs-core/test/create-node.spec.js
73:    const peerId = await PeerId.createFromPrivKey(`${config.Identity?.PrivKey}`)
129:    expect(config.Identity?.PrivKey.length).is.below(1024)
176:    expect(config.Addresses?.Swarm).to.eql(['/ip4/127.0.0.1/tcp/9977'])

./packages/ipfs-core/test/init.spec.js
96:    const peerId = await PeerId.createFromPrivKey(`${config.Identity?.PrivKey}`)
104:    const peerId = await PeerId.createFromPrivKey(`${config.Identity?.PrivKey}`)
112:    const peerId = await PeerId.createFromPrivKey(`${config.Identity?.PrivKey}`)
127:    expect(config.Identity?.PrivKey.length).is.above(256)
134:    expect(config.Identity?.PeerID).is.equal('QmRsooYQasV5f5r834NSpdUtmejdQcpxXkK6qsozZWEihC')
141:    expect(config.Identity?.PeerID).is.equal('12D3KooWRm8J3iL796zPFi2EtGGtUJn58AG67gcqzMFHZnnsTzqD')
148:    expect(config.Identity?.PeerID).is.equal('16Uiu2HAm5qw8UyXP2RLxQUx5KvtSN8DsTKz8quRGqGNC3SYiaB8E')
179:    expect(config.Discovery?.MDNS?.Enabled).to.be.true()

./packages/ipfs-http-server/src/index.js
139:    const enableCors = Boolean(cors.origin?.length)

./packages/ipfs-grpc-server/src/utils/web-socket-server.js
112:  const grpcAddr = config.Addresses?.RPC

./packages/ipfs-core/test/utils/mock-preload-node.js
31:    if (req.url?.startsWith('/api/v0/refs')) {

./packages/interface-ipfs-core/src/config/profiles/apply.js
31:      expect(diff.original.Swarm?.ConnMgr?.LowWater).to.not.equal(diff.updated.Swarm?.ConnMgr?.LowWater)
34:      expect(newConfig.Swarm?.ConnMgr?.LowWater).to.equal(diff.updated.Swarm?.ConnMgr?.LowWater)

That is why I ask how you are using and building this code, because it looks like a problem with your build setup or the way we support TS, not the ipfs-http-gateway code itself.

@dancingfrog
Copy link
Author

dancingfrog commented Oct 29, 2021

Thanks for explaining, @lidel

Hm.. iiuc ?. is not a typo, it is Optional Chaining and is used in other places as well:

So, in spite of the .js extension, that file is actually supposed to be transpiled with a TypeScript interpreter?

To answer your question, yes, I'm using Node to call this function, which works as soon as you remove the part of the syntax that is invalid JavaScript. TypeScript files usually use a .ts extension and mixing TypeScript syntax into presumed JavaScript code will lead to all kinds of problems. Maybe you can close this, while providing a link to what ever documentation explains why js-ipfs uses the .js file extension for TypeScript source code.

@dancingfrog dancingfrog reopened this Nov 9, 2021
@dancingfrog
Copy link
Author

After spending more time going through index.js I have concluded that this file is definitely not TypeScript... none of the variables have type declarations, which will always be an implicit error (Parameter 'XXX' implicitly has an 'any' type.). The content of index.s is certainly intended to be interpreted as JavaScript, so the use of the ?. syntax is an error in this context.

@achingbrain
Copy link
Member

This is not a TypeScript project, you are quite right. The optional chaining operator is available in JavaScript, but it is only supported by node 14+.

Are you using an older version?

@dancingfrog
Copy link
Author

dancingfrog commented Nov 9, 2021 via email

@dancingfrog dancingfrog closed this Nov 9, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants