Browse Source

ts: fix type for accounts field in Idl (#1542)

Krešimir Klas 3 years ago
parent
commit
946fa23538
2 changed files with 9 additions and 4 deletions
  1. 6 1
      ts/src/idl.ts
  2. 3 3
      ts/src/program/namespace/account.ts

+ 6 - 1
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;

+ 3 - 3
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 extends Idl> = IDL["accounts"] extends undefined
-  ? IdlTypeDef
+  ? IdlAccountDef
   : NonNullable<IDL["accounts"]>[number];
 
 /**
@@ -72,7 +72,7 @@ export type AccountNamespace<IDL extends Idl = Idl> = {
 export class AccountClient<
   IDL extends Idl = Idl,
   A extends NullableIdlAccount<IDL> = IDL["accounts"] extends undefined
-    ? IdlTypeDef
+    ? IdlAccountDef
     : NonNullable<IDL["accounts"]>[number],
   T = TypeDef<A, IdlTypes<IDL>>
 > {