ts: fill in some gaps for ts IDL types (#1393)

This commit is contained in:
Eoin Murphy 2022-02-04 18:11:17 +00:00 committed by GitHub
parent ba131265f8
commit 9fea72e701
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 0 deletions

View File

@ -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

View File

@ -92,6 +92,7 @@ export type MethodsFn<
type TypeMap = {
publicKey: PublicKey;
bool: boolean;
string: string;
} & {
[K in "u8" | "i8" | "u16" | "i16" | "u32" | "i32"]: number;
} &
@ -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] }