Browse Source

ts/namespace/index: fix undefined error from undefined idl.accounts

Chris Heaney 4 years ago
parent
commit
0a47d0d01e

+ 2 - 2
ts/src/program/namespace/account.ts

@@ -65,8 +65,8 @@ export default class AccountFactory {
  * For the full API, see the [[AccountClient]] reference.
  */
 export type AccountNamespace<IDL extends Idl = Idl> = {
-  [M in keyof AllAccountsMap<IDL>]: AccountClient<IDL>
-}
+  [M in keyof AllAccountsMap<IDL>]: AccountClient<IDL>;
+};
 
 export class AccountClient<
   IDL extends Idl = Idl,

+ 3 - 1
ts/src/program/namespace/index.ts

@@ -72,7 +72,9 @@ export default class NamespaceFactory {
       simulate[name] = simulateItem;
     });
 
-    const account = AccountFactory.build(idl, coder, programId, provider);
+    const account: AccountNamespace<IDL> = idl.accounts
+      ? AccountFactory.build(idl, coder, programId, provider)
+      : ({} as AccountNamespace<IDL>);
 
     return [
       rpc as RpcNamespace<IDL>,

+ 1 - 3
ts/src/program/namespace/types.ts

@@ -39,9 +39,7 @@ export type AccountMap<I extends IdlTypeDef> = {
 /**
  * Returns a type of instruction name to the IdlInstruction.
  */
-export type AllAccountsMap<IDL extends Idl> = AccountMap<
-    AllAccounts<IDL>
-    >;
+export type AllAccountsMap<IDL extends Idl> = AccountMap<AllAccounts<IDL>>;
 
 export type MakeInstructionsNamespace<
   IDL extends Idl,