coral-xyz / anchor

⚓ Solana Sealevel Framework
https://anchor-lang.com
Apache License 2.0
3.59k stars 1.32k forks source link

Object literal may only specify known properties #3086

Closed AuroraLantean closed 2 months ago

AuroraLantean commented 2 months ago

Although my Anchor tests can run fine, but my Vscode gave me this TypeScript warning:

Object literal may only specify known properties, and 'room' does not exist in type 'ResolvedAccounts<{ 
name: "room"; writable: true; pda: { seeds: [{ kind: "const"; value: [100, 101, ... ]; },
 { kind: "account"; path: "admin"; }]; }; } | 
{ name: "admin"; writable: true; signer: true; } | { ...; }>'.ts(2353)

This warning appears in my Anchor test file:

        await program.methods
            .add(bn(1820856857), bn(1830856857))
            .accounts({
                room: roomPublickey, // <--- Warning pointing at the "room"
                admin: provider.wallet.publicKey,
                systemProgram: anchor.web3.SystemProgram.programId,
            })
            .rpc();

My dependencies:

    "@coral-xyz/anchor": "^0.30.1",
    "@solana/web3.js": "^1.95.0"
    "@types/bn.js": "^5.1.5",
    "@types/chai": "^4.3.16",
    "@types/mocha": "^10.0.7",
    "chai": "^5.1.1",
    "mocha": "^10.6.0",
    "prettier": "^3.3.2",
    "ts-mocha": "^10.0.0",
    "typescript": "^5.5.3"

Is there extra TypeScript declaration missing? Thank you

acheroncrypto commented 2 months ago

It's because account resolution takes care of the room account (and also systemProgram). See https://solana.stackexchange.com/a/14345.

You can press CTRL+Space when your cursor is inside .accounts({...}) call to see which accounts are actually needed.