From 8c49e52b4bf1d2f841a7a52067cd9327c9e5558d Mon Sep 17 00:00:00 2001 From: Ghost Chain Date: Fri, 29 Oct 2021 16:43:59 -0400 Subject: [PATCH] Uncapitalize account names in the generated account map types --- ts/src/program/namespace/types.ts | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/ts/src/program/namespace/types.ts b/ts/src/program/namespace/types.ts index 49058bd6fe..e58477eec6 100644 --- a/ts/src/program/namespace/types.ts +++ b/ts/src/program/namespace/types.ts @@ -37,12 +37,22 @@ export type AllAccounts = IDL["accounts"] extends undefined ? IdlTypeDef : NonNullable[number]; +type UncapitalizeKeys = Uncapitalize; + +type UncapitalizeObjectKeys = { + [key in UncapitalizeKeys]: Capitalize extends keyof T + ? T[Capitalize] + : never; +}; + /** - * Returns a type of instruction name to the IdlInstruction. + * Returns a type of account name to the IdlTypeDef of the account. */ -export type AccountMap = { - [K in I["name"]]: I & { name: K }; -}; +export type AccountMap = UncapitalizeObjectKeys< + { + [K in I["name"]]: I & { name: K }; + } +>; /** * Returns a type of instruction name to the IdlInstruction.