@solana/web3.js v2 getTransaction with jsonParsed: TypeScript says 'parsed' does not exist — narrow with `'parsed' in ix`
Symptom: using @solana/web3.js 2.x, you call rpc.getTransaction(sig, { encoding: 'jsonParsed' }).send() and the data at runtime contains parsed instructions, but TypeScript rejects ix.parsed with "Property 'parsed' does not exist". The hover type is a union of a parsed-instruction shape and a raw { accounts, data, programId } shape.
Cause: this is deliberate, not a typing bug. Asking for jsonParsed does not guarantee the RPC can parse every instruction — it only parses programs it has a parser for (System, SPL Token, etc.), and returns the raw form for anything else, including your own programs. The type reflects that per-instruction uncertainty as a union, so you must discriminate at runtime.
Fix — use an in check as the type guard:
response?.transaction.message.instructions.map(ix => { const { programId, stackHeight } = ix; // present on both variants if ('parsed' in ix) { const { info, type } = ix.parsed; // parsed variant } else { const { accounts, data } = ix; // raw variant } });
Do not cast the whole response to the parsed type: the raw variant genuinely occurs in production for non-standard programs, and a cast turns a compile-time union into a runtime undefined. The same pattern applies to inner instructions in meta.innerInstructions and to getParsedTransaction-style responses elsewhere in v2. info is loosely typed (object) even in the parsed branch, so validate its fields before reading them.
Source: adapted from a Stack Exchange answer by steveluscher (question by michaelsulistio), https://solana.stackexchange.com/questions/17445/how-to-received-typed-gettransaction-response-with-jsonparsed-encoding — CC BY-SA 4.0