From a08ba5e31e90bf3208919bc1d5e08c1ba9524130 Mon Sep 17 00:00:00 2001 From: Kevin Ingersoll Date: Fri, 20 Sep 2024 12:19:43 +0000 Subject: [PATCH] fix(store): better enumValues type (#3211) --- .changeset/red-gifts-cheat.md | 5 +++++ packages/store/ts/config/v2/enums.ts | 2 +- packages/store/ts/config/v2/store.test.ts | 7 ++++++- 3 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 .changeset/red-gifts-cheat.md diff --git a/.changeset/red-gifts-cheat.md b/.changeset/red-gifts-cheat.md new file mode 100644 index 0000000000..5b65e3be48 --- /dev/null +++ b/.changeset/red-gifts-cheat.md @@ -0,0 +1,5 @@ +--- +"@latticexyz/store": patch +--- + +Improved config output type of `enumValues`. diff --git a/packages/store/ts/config/v2/enums.ts b/packages/store/ts/config/v2/enums.ts index 92d2f2de8e..c46623b319 100644 --- a/packages/store/ts/config/v2/enums.ts +++ b/packages/store/ts/config/v2/enums.ts @@ -38,7 +38,7 @@ export function resolveEnums(enums: enums): resolveEnu export type mapEnums = { readonly [key in keyof enums]: { - readonly [element in keyof enums[key] as enums[key][element] & string]: parseNumber; + readonly [element in keyof enums[key] & `${number}` as enums[key][element] & string]: parseNumber; }; }; diff --git a/packages/store/ts/config/v2/store.test.ts b/packages/store/ts/config/v2/store.test.ts index 9357f192fb..170540c278 100644 --- a/packages/store/ts/config/v2/store.test.ts +++ b/packages/store/ts/config/v2/store.test.ts @@ -766,7 +766,12 @@ describe("defineStore", () => { First: 0, Second: 1, }, - }); + }).type.toString.snap(`{ + readonly Example: { + readonly First: 0 + readonly Second: 1 + } +}`); }); it("should allow a const config as input", () => {