Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ts: instanceof PublicKey not working #1101

Closed
paul-schaaf opened this issue Dec 4, 2021 · 5 comments
Closed

ts: instanceof PublicKey not working #1101

paul-schaaf opened this issue Dec 4, 2021 · 5 comments
Labels
help wanted Extra attention is needed ts

Comments

@paul-schaaf
Copy link
Contributor

I discovered this while working on #1098

The PR adds an error that is thrown when translateAddress receives an object that is not a string or a public key so that callers of the function can handle it.

I initially tried using address instanceof PublicKey for this but it made some tests fail by throwing the error so I thought these tests are passing something else into translateAddress and the test is written wrong. But it isnt. I logged the prototype chain of what is actually passed in in the test and it is a PublicKey.

e.g.

🚨🚨🚨🚨🚨🚨
PublicKey {
  _bn: <BN: a90a662a139208a9b9f0d7de6e5577324bf718f3e416fc0e23d4e0fdd256c82f>
}
 -> PublicKey -> Struct -> Object

but for some reason instanceof PublicKey fails

@paul-schaaf paul-schaaf added help wanted Extra attention is needed ts labels Dec 4, 2021
@fanatid
Copy link
Contributor

fanatid commented Dec 4, 2021

Maybe PublicKey comes from different package locations?
What npm why @solana/web3.js show?

@paul-schaaf
Copy link
Contributor Author

there is no command npm why for me

I also tried doing sth like instance of @solana/web3.js.Pubkey || instance of anchor.web3.Pubkey to no avail

@fanatid
Copy link
Contributor

fanatid commented Dec 4, 2021

Maybe old node version?

$ npm why @solana/web3.js
@solana/web3.js@1.30.2
node_modules/@solana/web3.js
  @solana/web3.js@"^1.17.0" from @project-serum/anchor@0.18.0
  node_modules/@project-serum/anchor
    @project-serum/anchor@"=0.18.0" from the root project
  peer @solana/web3.js@"^1.2.0" from @project-serum/borsh@0.2.2
  node_modules/@project-serum/borsh
    @project-serum/borsh@"^0.2.2" from @project-serum/anchor@0.18.0
    node_modules/@project-serum/anchor
      @project-serum/anchor@"=0.18.0" from the root project
    @project-serum/borsh@"^0.2.2" from @project-serum/anchor@0.11.1
    node_modules/@project-serum/serum/node_modules/@project-serum/anchor
      @project-serum/anchor@"^0.11.1" from @project-serum/serum@0.13.60
      node_modules/@project-serum/serum
        dev @project-serum/serum@"^0.13.41" from the root project
  @solana/web3.js@"^1.21.0" from @project-serum/serum@0.13.60
  node_modules/@project-serum/serum
    dev @project-serum/serum@"^0.13.41" from the root project
  @solana/web3.js@"^1.17.0" from @project-serum/anchor@0.11.1
  node_modules/@project-serum/serum/node_modules/@project-serum/anchor
    @project-serum/anchor@"^0.11.1" from @project-serum/serum@0.13.60
    node_modules/@project-serum/serum
      dev @project-serum/serum@"^0.13.41" from the root project
  @solana/web3.js@"^1.21.0" from @solana/spl-token@0.1.8
  node_modules/@solana/spl-token
    dev @solana/spl-token@"^0.1.8" from the root project
    @solana/spl-token@"^0.1.6" from @project-serum/serum@0.13.60
    node_modules/@project-serum/serum
      dev @project-serum/serum@"^0.13.41" from the root project
$ node --version
v17.2.0
$ npm --version
8.1.4

@paul-schaaf
Copy link
Contributor Author

just updated to lts, same issue still occurs

@paul-schaaf
Copy link
Contributor Author

im closing this for now until it shows up somewhere else and causes problems because #1138 has a better fix than #1098

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed ts
Projects
None yet
Development

No branches or pull requests

2 participants