anchor
anchor copied to clipboard
BUG [TypeScript] Program problem with vector of defined type
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.
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.
Fixed in https://github.com/coral-xyz/anchor/pull/2176.