anchor icon indicating copy to clipboard operation
anchor copied to clipboard

BUG [TypeScript] Program problem with vector of defined type

Open tallalnparis4ev opened this issue 2 years ago • 1 comments

Hello, the problem is in the last line. I believe there's a problem in having vectors of defined types.

type HelpMe = {
    "version": "1.0.0",
    "name": "tester",
    "instructions": [],
    "accounts": [
      {
        "name": "test",
        "type": {
          "kind": "struct",
          "fields": [
            {
              "name": "vecExample",
              "type":{
                "vec": {
                  "defined": "TestDefined"
                }
              }
            }
          ]
        }
      },
    ],
    "types": [{
      "name": "TestDefined",
      "type": {
        "kind": "struct",
        "fields": [
          {
            "name": "testField",
            "type": "u8"
          }
        ]
      }
    }],
    "events": [],
    "errors": []
  };

  const testProgram = new Program<HelpMe>(
    "who cares about this IDL" as any,
    "",
    anchor.getProvider(),
  );

  const test = await testProgram.account.test.fetch("a");
  test.vecExample // The problem is here, shouldn't vecExample be of type TestDefined[] ? Instead it is of type 'unknown'

Before anyone asks, I manually created the type HelpMe. BUT it is a minimal example to reproduce the error I was seeing from an Anchor generated type.

tallalnparis4ev avatar May 21 '22 12:05 tallalnparis4ev

Having same issue. The odd thing was I wasn't having this issue before, didn't update any packages or anything. Ran anchor build and then suddenly started to get the error.

ogmedia avatar Jun 21 '22 07:06 ogmedia

Fixed in https://github.com/coral-xyz/anchor/pull/2176.

acheroncrypto avatar Sep 29 '23 07:09 acheroncrypto