-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Account context codegen for TypeScript #3477
Comments
All client-side types should get updated automatically once you update your IDL. Could you share a snippet regarding where you need to manually update? |
@acheroncrypto thanks for your response. Where are the client side types supposed to be located? From what I can tell, the expectation on the Contrast this in Rust, where there is the Maybe I am missing something. |
We do not generate hardcoded types for TypeScript (all types are inferred from the generated IDL type). This is different for Rust because there is no way to do what's possible on TypeScript (inferring types) in Rust. We do have utility types to get certain types, e.g. accounts, but we don't have one specific for instruction accounts. We could add something like: type InstructionAccounts<
I extends anchor.Idl,
N extends I["instructions"][number]["name"],
Ixs extends I["instructions"] = I["instructions"]
> = Ixs extends [infer Head, ...infer Tail]
? Head extends { name: N }
? anchor.Accounts<Head>[N]
: Tail extends Ixs
? InstructionAccounts<I, N, Tail>
: never
: never; And you'd use it as: type MyIxAccounts = InstructionAccounts<MyIdl, "myIx">; Would this be useful to you? I know it's not exactly what you want, but pretty much anything you need can be derived from the generated IDL type without having to hardcode them. |
Oh this is very powerful, will try it out when availabile @acheroncrypto thank you. Despite Rust having the more sound type system, TypeScript does simulate some very cool typelevel calculations. |
Currently it seems like only the Rust side of Anchor has all of the instruction account contexts generated as structs. It would be nice if the Typescript side had the same. We are finding it cumbersome to constantly update fields in client-side types when contracts change by one or two accounts.
The text was updated successfully, but these errors were encountered: