From 946fa2353864b8fd806cfc993ca590da975e4f26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kre=C5=A1imir=20Klas?= Date: Wed, 23 Mar 2022 02:43:51 +0100 Subject: [PATCH] ts: fix type for accounts field in Idl (#1542) --- ts/src/idl.ts | 7 ++++++- ts/src/program/namespace/account.ts | 6 +++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/ts/src/idl.ts b/ts/src/idl.ts index 7587c1a48..3fe002bd8 100644 --- a/ts/src/idl.ts +++ b/ts/src/idl.ts @@ -7,7 +7,7 @@ export type Idl = { name: string; instructions: IdlInstruction[]; state?: IdlState; - accounts?: IdlTypeDef[]; + accounts?: IdlAccountDef[]; types?: IdlTypeDef[]; events?: IdlEvent[]; errors?: IdlErrorCode[]; @@ -79,6 +79,11 @@ export type IdlTypeDef = { type: IdlTypeDefTy; }; +export type IdlAccountDef = { + name: string; + type: IdlTypeDefTyStruct; +}; + export type IdlTypeDefTyStruct = { kind: "struct"; fields: IdlTypeDefStruct; diff --git a/ts/src/program/namespace/account.ts b/ts/src/program/namespace/account.ts index 3793cfc6c..5563900c5 100644 --- a/ts/src/program/namespace/account.ts +++ b/ts/src/program/namespace/account.ts @@ -10,7 +10,7 @@ import { AccountInfo, } from "@solana/web3.js"; import Provider, { getProvider } from "../../provider.js"; -import { Idl, IdlTypeDef } from "../../idl.js"; +import { Idl, IdlAccountDef } from "../../idl.js"; import { Coder, BorshCoder } from "../../coder/index.js"; import { Subscription, Address, translateAddress } from "../common.js"; import { AllAccountsMap, IdlTypes, TypeDef } from "./types.js"; @@ -42,7 +42,7 @@ export default class AccountFactory { } type NullableIdlAccount = IDL["accounts"] extends undefined - ? IdlTypeDef + ? IdlAccountDef : NonNullable[number]; /** @@ -72,7 +72,7 @@ export type AccountNamespace = { export class AccountClient< IDL extends Idl = Idl, A extends NullableIdlAccount = IDL["accounts"] extends undefined - ? IdlTypeDef + ? IdlAccountDef : NonNullable[number], T = TypeDef> > {