Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ts: AccountClient isn't properly typed #1706

Closed
callensm opened this issue Mar 29, 2022 · 6 comments
Closed

ts: AccountClient isn't properly typed #1706

callensm opened this issue Mar 29, 2022 · 6 comments
Labels
bug Something isn't working ts

Comments

@callensm
Copy link
Member

callensm commented Mar 29, 2022

Querying for accounts like program.account.myAccount.fetch(addr) should return an object that is strictly typed for the myAccount account type definition.

However, the client currently types the object as being the union of properties between all IDL defined account structs.

image

As seen in the screenshot, the typing on the listing account client includes the properties of other account types.

@callensm
Copy link
Member Author

It is because of:
https://github.com/project-serum/anchor/blob/master/ts/src/program/namespace/account.ts#L46
and
https://github.com/project-serum/anchor/blob/master/ts/src/program/namespace/account.ts#L76

which are saying that the type if an arbitrary index of the accounts array in the IDL, allow the type definition to become the union of all available.

@paul-schaaf paul-schaaf added bug Something isn't working ts labels Mar 31, 2022
@paul-schaaf
Copy link
Contributor

paul-schaaf commented Mar 31, 2022

probably for the same reason, program.methods.accounts({ .. }) is also not typed properly

@callensm
Copy link
Member Author

callensm commented Apr 1, 2022

the MethodsBuilder.accounts function typings should have been fixed in a PR I submitted about a month ago.

@paul-schaaf
Copy link
Contributor

it it fixed for you? its not working for me

@callensm
Copy link
Member Author

callensm commented Apr 1, 2022

ahhh, it works as expected as a chain onto the instruction, e.g.:

program
  .methods
  .initAccount()
  .accounts({ ... })
  // ...

but using it prior to the instruction would cause issues because the typings don't know which instruction has been selected yet to pull the account names for.

@acheroncrypto
Copy link
Collaborator

Fixed in #2440

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working ts
Projects
None yet
Development

No branches or pull requests

3 participants