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

Trying to use coption / COption #50

Open
olivbau opened this issue Jan 27, 2023 · 1 comment
Open

Trying to use coption / COption #50

olivbau opened this issue Jan 27, 2023 · 1 comment

Comments

@olivbau
Copy link

olivbau commented Jan 27, 2023

I'm trying to use coption / COption
I use the code provided by the doc

Code used:

import * as web3 from '@solana/web3.js';
import * as beet from '@metaplex-foundation/beet';
import * as beetSolana from '@metaplex-foundation/beet-solana';

type InstructionArgs = {
  authority: web3.PublicKey;
  maybePublickKey: beet.COption<web3.PublicKey>;
};

// Uses the BeetArgsStruct wrapper around BeetStruct
const createStruct = new beet.BeetArgsStruct<InstructionArgs>(
  [
    ['authority', beetSolana.publicKey],
    ['maybePublickKey', beet.coption(beetSolana.publicKey)],
  ],
  'InstructionArgs'
);

But I have a typescript error on beet.coption(beetSolana.publicKey)
Do you have any idea where it came from?

Error:

Type 'FixableBeet<COption<PublicKey>, Partial<COption<PublicKey>>>' is missing the following properties from type 'BeetReadWrite<COption<PublicKey>, Partial<COption<PublicKey>>>': write, read, byteSize

image

@olivbau olivbau changed the title Trying to use coption Trying to use coption / COption Jan 27, 2023
@staccDOTsol
Copy link

This error message is indicating that the coption function is returning a FixableBeet type instead of a BeetReadWrite type. This is likely due to a version mismatch between the @metaplex-foundation/beet and @metaplex-foundation/beet-solana packages.

Try updating both packages to the latest version and see if the error persists. You can do this by running the following command in your terminal:

npm install @metaplex-foundation/beet @metaplex-foundation/beet-solana@latest

If the error still persists, you can try explicitly casting the return value of coption to BeetReadWrite like this:

['maybePublickKey', beet.coption(beetSolana.publicKey) as beet.BeetReadWrite<beet.COption<web3.PublicKey>, Partial<beet.COption<web3.PublicKey>>>],

This should resolve the error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants