When referencing Solana documentation, TypeScript code snippets are commonly used. For instance, in the link provided below (the first code snippet) should be executed to return a value:
I attempted to execute the initial snippet using: ts-node file.ts
, however I encountered the following error:
return new TSError(diagnosticText, diagnosticCodes);
^
TSError: ⨯ Unable to compile TypeScript:
index.ts:33:26 - error TS7053: Element implicitly has an 'any' type because expression of type '"parsed"' can't be used to index type 'Buffer | ParsedAccountData'.
Property 'parsed' does not exist on type 'Buffer | ParsedAccountData'.
33 console.log(`Mint: ${account.account.data["parsed"]["info"]["mint"]}`);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
index.ts:35:18 - error TS7053: Element implicitly has an 'any' type because expression of type '"parsed"' can't be used to index type 'Buffer | ParsedAccountData'.
Property 'parsed' does not exist on type 'Buffer | ParsedAccountData'.
35 `Amount: ${account.account.data["parsed"]["info"]["tokenAmount"]["uiAmount"]}`
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
at createTSError (/usr/local/lib/node_modules/ts-node/src/index.ts:750:12)
at reportTSError (/usr/local/lib/node_modules/ts-node/src/index.ts:754:19)
at getOutput (/usr/local/lib/node_modules/ts-node/src/index.ts:941:36)
at Object.compile (/usr/local/lib/node_modules/ts-node/src/index.ts:1243:30)
at Module.m._compile (/usr/local/lib/node_modules/ts-node/src/index.ts:1370:30)
at Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
at Object.require.extensions.<computed> [as .ts] (/usr/local/lib/node_modules/ts-node/src/index.ts:1374:12)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12) {
diagnosticText: `\x1B[96mindex.ts\x1B[0m:\x1B[93m33\x1B[0m:\x1B[93m26\x1B[0m - \x1B[91merror\x1B[0m\x1B[90m TS7053: \x1B[0mElement implicitly has an 'any' type because expression of type '"parsed"' can't be used to index type 'Buffer | ParsedAccountData'.\n` +
" Property 'parsed' does not exist on type 'Buffer | ParsedAccountData'.\n" +
'\n' +
'\x1B[7m33\x1B[0m console.log(`Mint: ${account.account.data["parsed"]["info"]["mint"]}`);\n' +
'\x1B[7m \x1B[0m \x1B[91m ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\x1B[0m\n' +
`\x1B[96mindex.ts\x1B[0m:\x1B[93m35\x1B[0m:\x1B[93m18\x1B[0m - \x1B[91merror\x1B[0m\x1B[90m TS7053: \x1B[0mElement implicitly has an 'any' type because expression of type '"parsed"' can't be used to index type 'Buffer | ParsedAccountData'.\n` +
" Property 'parsed' does not exist on type 'Buffer | ParsedAccountData'.\n" +
'\n' +
'\x1B[7m35\x1B[0m `Amount: ${account.account.data["parsed"]["info"]["tokenAmount"]["uiAmount"]}`\n' +
'\x1B[7m \x1B[0m \x1B[91m ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\x1B[0m\n',
diagnosticCodes: [ 7053, 7053 ]
}
Is my approach correct?