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

Gaps in generated types for Typescript (Option and Vec<String>) #1392

Closed
eoin-betdex opened this issue Feb 4, 2022 · 0 comments · Fixed by #1393
Closed

Gaps in generated types for Typescript (Option and Vec<String>) #1392

eoin-betdex opened this issue Feb 4, 2022 · 0 comments · Fixed by #1393

Comments

@eoin-betdex
Copy link
Contributor

We've run up against two small issues when working in Typescript with the types generated for account fields from the IDLs.

  1. Option<T> fields map to unknown type in Typescript when T is one of the standard types defined in TypeMap, e.g.,
#[account]
pub struct MyAccount {
    pub counter: Option<u16>,
}
const accountAddress = "...";
const myAccount = await myProgram.account.myAccount.fetch(accountAddress);
const counterPlusOne = myAccount.counter + 1;  // Assuming the counter has been initialised

Results in TS2365: Operator '+' cannot be applied to types 'unknown' and '1'.

  1. Vec<String> fields map to unknown type in Typescript. Only the types defined in TypeMap are considered when determining how to map a Vec<T> to some T'[].
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant