ts: fix type for accounts field in Idl (#1542)
This commit is contained in:
parent
811a4cb318
commit
946fa23538
|
@ -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;
|
||||
|
|
|
@ -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>>
|
||||
> {
|
||||
|
|
Loading…
Reference in New Issue