0

As you can see in screenshots, I have a type error. How can I avoid this problem ?

IDE Type description

IDE Type error

The type of my transaction is 'ParsedTransactionWithMeta' from getParsedTransaction method.

Same problem with 'accounts'. Accounts exist in PartiallyDecodedInstruction, and parsed exist on ParsedInstruction IDE Accounts problem description

1 Answer 1

1

As you've already figured out the type ParsedInnerInstruction uses | operator, and accounts and parsed properties are only available in one of the types.

type ParsedInnerInstruction = {
  instructions: (ParsedInstruction | PartiallyDecodedInstruction)[];
};

To fix this you can explicitly narrow down type checking using conditionals, i,e

const instruction = instructions[i]; 

if ('parsed' in instruction) { 
  // access parsed property
} 
if ('accounts' in instruction) { 
 // access account property
}

This way TS can infer the type.

1
  • How come this is 'any' in the typescript docs. /** Parsed instruction info */ parsed: any; Commented Apr 9 at 22:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.