Skip to content

Commit

Permalink
ts: fill in some gaps for ts IDL types (coral-xyz#1393)
Browse files Browse the repository at this point in the history
  • Loading branch information
eoin-betdex authored and losman0s committed Feb 7, 2022
1 parent 06d1c7f commit 8997de5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -14,6 +14,7 @@ incremented for features.
### Fixes

* ts: Fix the root type declaration of the `Wallet` / `NodeWallet` class. ([#1363](https://github.com/project-serum/anchor/pull/1363))
* ts: Improve type mapping of Account fields into Typescript with additional support for `Option<T>` and `Vec<String>` types. ([#1393](https://github.com/project-serum/anchor/pull/1393))

### Features

Expand Down
3 changes: 3 additions & 0 deletions ts/src/program/namespace/types.ts
Expand Up @@ -92,6 +92,7 @@ export type MethodsFn<
type TypeMap = {
publicKey: PublicKey;
bool: boolean;
string: string;
} & {
[K in "u8" | "i8" | "u16" | "i16" | "u32" | "i32"]: number;
} &
Expand All @@ -105,6 +106,8 @@ export type DecodeType<T extends IdlType, Defined> = T extends keyof TypeMap
? Defined[T["defined"]]
: T extends { option: { defined: keyof Defined } }
? Defined[T["option"]["defined"]] | null
: T extends { option: keyof TypeMap }
? TypeMap[T["option"]]
: T extends { vec: keyof TypeMap }
? TypeMap[T["vec"]][]
: T extends { array: [defined: keyof TypeMap, size: number] }
Expand Down

0 comments on commit 8997de5

Please sign in to comment.