beet
beet copied to clipboard
Trying to use coption / COption
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
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.