From 808e6672b6a53b5664d4e04b7d8d22c395a3d637 Mon Sep 17 00:00:00 2001 From: Kevin Ingersoll Date: Fri, 20 Sep 2024 12:13:46 +0100 Subject: [PATCH 1/3] show bad enumValues type --- packages/store/ts/config/v2/store.test.ts | 327 +++++++++++++++++++++- 1 file changed, 326 insertions(+), 1 deletion(-) diff --git a/packages/store/ts/config/v2/store.test.ts b/packages/store/ts/config/v2/store.test.ts index 9357f192fb..c39970f15a 100644 --- a/packages/store/ts/config/v2/store.test.ts +++ b/packages/store/ts/config/v2/store.test.ts @@ -766,7 +766,332 @@ describe("defineStore", () => { First: 0, Second: 1, }, - }); + }).type.toString.snap(`{ + readonly Example: { + readonly [x: (() => string) & string]: never + readonly [x: (() => string) & string]: never + readonly [ + x: { + ( + ...items: ConcatArray<"First" | "Second">[] + ): ("First" | "Second")[] + ( + ...items: ( + | "First" + | "Second" + | ConcatArray<"First" | "Second"> + )[] + ): ("First" | "Second")[] + } & string + ]: never + readonly [ + x: ((separator?: string | undefined) => string) & + string + ]: never + readonly [ + x: (( + start?: number | undefined, + end?: number | undefined + ) => ("First" | "Second")[]) & + string + ]: never + readonly [ + x: (( + searchElement: "First" | "Second", + fromIndex?: number | undefined + ) => number) & + string + ]: never + readonly [ + x: (( + searchElement: "First" | "Second", + fromIndex?: number | undefined + ) => number) & + string + ]: never + readonly [ + x: { + ( + predicate: ( + value: "First" | "Second", + index: number, + array: readonly ("First" | "Second")[] + ) => value is S, + thisArg?: any + ): this is readonly S[] + ( + predicate: ( + value: "First" | "Second", + index: number, + array: readonly ("First" | "Second")[] + ) => unknown, + thisArg?: any + ): boolean + } & string + ]: never + readonly [ + x: (( + predicate: ( + value: "First" | "Second", + index: number, + array: readonly ("First" | "Second")[] + ) => unknown, + thisArg?: any + ) => boolean) & + string + ]: never + readonly [ + x: (( + callbackfn: ( + value: "First" | "Second", + index: number, + array: readonly ("First" | "Second")[] + ) => void, + thisArg?: any + ) => void) & + string + ]: never + readonly [ + x: (( + callbackfn: ( + value: "First" | "Second", + index: number, + array: readonly ("First" | "Second")[] + ) => U, + thisArg?: any + ) => U[]) & + string + ]: never + readonly [ + x: { + ( + predicate: ( + value: "First" | "Second", + index: number, + array: readonly ("First" | "Second")[] + ) => value is S, + thisArg?: any + ): S[] + ( + predicate: ( + value: "First" | "Second", + index: number, + array: readonly ("First" | "Second")[] + ) => unknown, + thisArg?: any + ): ("First" | "Second")[] + } & string + ]: never + readonly [ + x: { + ( + callbackfn: ( + previousValue: "First" | "Second", + currentValue: "First" | "Second", + currentIndex: number, + array: readonly ("First" | "Second")[] + ) => "First" | "Second" + ): "First" | "Second" + ( + callbackfn: ( + previousValue: "First" | "Second", + currentValue: "First" | "Second", + currentIndex: number, + array: readonly ("First" | "Second")[] + ) => "First" | "Second", + initialValue: "First" | "Second" + ): "First" | "Second" + ( + callbackfn: ( + previousValue: U, + currentValue: "First" | "Second", + currentIndex: number, + array: readonly ("First" | "Second")[] + ) => U, + initialValue: U + ): U + } & string + ]: never + readonly [ + x: { + ( + callbackfn: ( + previousValue: "First" | "Second", + currentValue: "First" | "Second", + currentIndex: number, + array: readonly ("First" | "Second")[] + ) => "First" | "Second" + ): "First" | "Second" + ( + callbackfn: ( + previousValue: "First" | "Second", + currentValue: "First" | "Second", + currentIndex: number, + array: readonly ("First" | "Second")[] + ) => "First" | "Second", + initialValue: "First" | "Second" + ): "First" | "Second" + ( + callbackfn: ( + previousValue: U, + currentValue: "First" | "Second", + currentIndex: number, + array: readonly ("First" | "Second")[] + ) => U, + initialValue: U + ): U + } & string + ]: never + readonly [ + x: { + ( + predicate: ( + value: "First" | "Second", + index: number, + obj: readonly ("First" | "Second")[] + ) => value is S, + thisArg?: any + ): S | undefined + ( + predicate: ( + value: "First" | "Second", + index: number, + obj: readonly ("First" | "Second")[] + ) => unknown, + thisArg?: any + ): "First" | "Second" | undefined + } & string + ]: never + readonly [ + x: (( + predicate: ( + value: "First" | "Second", + index: number, + obj: readonly ("First" | "Second")[] + ) => unknown, + thisArg?: any + ) => number) & + string + ]: never + readonly [ + x: (() => IterableIterator< + [number, "First" | "Second"] + >) & + string + ]: never + readonly [ + x: (() => IterableIterator) & string + ]: never + readonly [ + x: (() => IterableIterator<"First" | "Second">) & + string + ]: never + readonly [ + x: (( + searchElement: "First" | "Second", + fromIndex?: number | undefined + ) => boolean) & + string + ]: never + readonly [ + x: (( + callback: ( + this: This, + value: "First" | "Second", + index: number, + array: ("First" | "Second")[] + ) => U | readonly U[], + thisArg?: This | undefined + ) => U[]) & + string + ]: never + readonly [ + x: (( + this: A, + depth?: D | undefined + ) => FlatArray[]) & + string + ]: never + readonly [ + x: (( + index: number + ) => "First" | "Second" | undefined) & + string + ]: never + readonly [ + x: { + ( + predicate: ( + value: "First" | "Second", + index: number, + array: readonly ("First" | "Second")[] + ) => value is S, + thisArg?: any + ): S | undefined + ( + predicate: ( + value: "First" | "Second", + index: number, + array: readonly ("First" | "Second")[] + ) => unknown, + thisArg?: any + ): "First" | "Second" | undefined + } & string + ]: never + readonly [ + x: (( + predicate: ( + value: "First" | "Second", + index: number, + array: readonly ("First" | "Second")[] + ) => unknown, + thisArg?: any + ) => number) & + string + ]: never + readonly [ + x: (() => ("First" | "Second")[]) & string + ]: never + readonly [ + x: (( + compareFn?: + | (( + a: "First" | "Second", + b: "First" | "Second" + ) => number) + | undefined + ) => ("First" | "Second")[]) & + string + ]: never + readonly [ + x: { + ( + start: number, + deleteCount: number, + ...items: ("First" | "Second")[] + ): ("First" | "Second")[] + ( + start: number, + deleteCount?: number | undefined + ): ("First" | "Second")[] + } & string + ]: never + readonly [ + x: (( + index: number, + value: "First" | "Second" + ) => ("First" | "Second")[]) & + string + ]: never + readonly [ + x: (() => IterableIterator<"First" | "Second">) & + string + ]: never + readonly [x: never]: never + readonly First: 0 + readonly Second: 1 + } +}`); }); it("should allow a const config as input", () => { From f7ff7057b90803047db6d602a48b851aeff114ca Mon Sep 17 00:00:00 2001 From: Kevin Ingersoll Date: Fri, 20 Sep 2024 12:15:54 +0100 Subject: [PATCH 2/3] fix type --- packages/store/ts/config/v2/enums.ts | 2 +- packages/store/ts/config/v2/store.test.ts | 320 ---------------------- 2 files changed, 1 insertion(+), 321 deletions(-) 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 c39970f15a..170540c278 100644 --- a/packages/store/ts/config/v2/store.test.ts +++ b/packages/store/ts/config/v2/store.test.ts @@ -768,326 +768,6 @@ describe("defineStore", () => { }, }).type.toString.snap(`{ readonly Example: { - readonly [x: (() => string) & string]: never - readonly [x: (() => string) & string]: never - readonly [ - x: { - ( - ...items: ConcatArray<"First" | "Second">[] - ): ("First" | "Second")[] - ( - ...items: ( - | "First" - | "Second" - | ConcatArray<"First" | "Second"> - )[] - ): ("First" | "Second")[] - } & string - ]: never - readonly [ - x: ((separator?: string | undefined) => string) & - string - ]: never - readonly [ - x: (( - start?: number | undefined, - end?: number | undefined - ) => ("First" | "Second")[]) & - string - ]: never - readonly [ - x: (( - searchElement: "First" | "Second", - fromIndex?: number | undefined - ) => number) & - string - ]: never - readonly [ - x: (( - searchElement: "First" | "Second", - fromIndex?: number | undefined - ) => number) & - string - ]: never - readonly [ - x: { - ( - predicate: ( - value: "First" | "Second", - index: number, - array: readonly ("First" | "Second")[] - ) => value is S, - thisArg?: any - ): this is readonly S[] - ( - predicate: ( - value: "First" | "Second", - index: number, - array: readonly ("First" | "Second")[] - ) => unknown, - thisArg?: any - ): boolean - } & string - ]: never - readonly [ - x: (( - predicate: ( - value: "First" | "Second", - index: number, - array: readonly ("First" | "Second")[] - ) => unknown, - thisArg?: any - ) => boolean) & - string - ]: never - readonly [ - x: (( - callbackfn: ( - value: "First" | "Second", - index: number, - array: readonly ("First" | "Second")[] - ) => void, - thisArg?: any - ) => void) & - string - ]: never - readonly [ - x: (( - callbackfn: ( - value: "First" | "Second", - index: number, - array: readonly ("First" | "Second")[] - ) => U, - thisArg?: any - ) => U[]) & - string - ]: never - readonly [ - x: { - ( - predicate: ( - value: "First" | "Second", - index: number, - array: readonly ("First" | "Second")[] - ) => value is S, - thisArg?: any - ): S[] - ( - predicate: ( - value: "First" | "Second", - index: number, - array: readonly ("First" | "Second")[] - ) => unknown, - thisArg?: any - ): ("First" | "Second")[] - } & string - ]: never - readonly [ - x: { - ( - callbackfn: ( - previousValue: "First" | "Second", - currentValue: "First" | "Second", - currentIndex: number, - array: readonly ("First" | "Second")[] - ) => "First" | "Second" - ): "First" | "Second" - ( - callbackfn: ( - previousValue: "First" | "Second", - currentValue: "First" | "Second", - currentIndex: number, - array: readonly ("First" | "Second")[] - ) => "First" | "Second", - initialValue: "First" | "Second" - ): "First" | "Second" - ( - callbackfn: ( - previousValue: U, - currentValue: "First" | "Second", - currentIndex: number, - array: readonly ("First" | "Second")[] - ) => U, - initialValue: U - ): U - } & string - ]: never - readonly [ - x: { - ( - callbackfn: ( - previousValue: "First" | "Second", - currentValue: "First" | "Second", - currentIndex: number, - array: readonly ("First" | "Second")[] - ) => "First" | "Second" - ): "First" | "Second" - ( - callbackfn: ( - previousValue: "First" | "Second", - currentValue: "First" | "Second", - currentIndex: number, - array: readonly ("First" | "Second")[] - ) => "First" | "Second", - initialValue: "First" | "Second" - ): "First" | "Second" - ( - callbackfn: ( - previousValue: U, - currentValue: "First" | "Second", - currentIndex: number, - array: readonly ("First" | "Second")[] - ) => U, - initialValue: U - ): U - } & string - ]: never - readonly [ - x: { - ( - predicate: ( - value: "First" | "Second", - index: number, - obj: readonly ("First" | "Second")[] - ) => value is S, - thisArg?: any - ): S | undefined - ( - predicate: ( - value: "First" | "Second", - index: number, - obj: readonly ("First" | "Second")[] - ) => unknown, - thisArg?: any - ): "First" | "Second" | undefined - } & string - ]: never - readonly [ - x: (( - predicate: ( - value: "First" | "Second", - index: number, - obj: readonly ("First" | "Second")[] - ) => unknown, - thisArg?: any - ) => number) & - string - ]: never - readonly [ - x: (() => IterableIterator< - [number, "First" | "Second"] - >) & - string - ]: never - readonly [ - x: (() => IterableIterator) & string - ]: never - readonly [ - x: (() => IterableIterator<"First" | "Second">) & - string - ]: never - readonly [ - x: (( - searchElement: "First" | "Second", - fromIndex?: number | undefined - ) => boolean) & - string - ]: never - readonly [ - x: (( - callback: ( - this: This, - value: "First" | "Second", - index: number, - array: ("First" | "Second")[] - ) => U | readonly U[], - thisArg?: This | undefined - ) => U[]) & - string - ]: never - readonly [ - x: (( - this: A, - depth?: D | undefined - ) => FlatArray[]) & - string - ]: never - readonly [ - x: (( - index: number - ) => "First" | "Second" | undefined) & - string - ]: never - readonly [ - x: { - ( - predicate: ( - value: "First" | "Second", - index: number, - array: readonly ("First" | "Second")[] - ) => value is S, - thisArg?: any - ): S | undefined - ( - predicate: ( - value: "First" | "Second", - index: number, - array: readonly ("First" | "Second")[] - ) => unknown, - thisArg?: any - ): "First" | "Second" | undefined - } & string - ]: never - readonly [ - x: (( - predicate: ( - value: "First" | "Second", - index: number, - array: readonly ("First" | "Second")[] - ) => unknown, - thisArg?: any - ) => number) & - string - ]: never - readonly [ - x: (() => ("First" | "Second")[]) & string - ]: never - readonly [ - x: (( - compareFn?: - | (( - a: "First" | "Second", - b: "First" | "Second" - ) => number) - | undefined - ) => ("First" | "Second")[]) & - string - ]: never - readonly [ - x: { - ( - start: number, - deleteCount: number, - ...items: ("First" | "Second")[] - ): ("First" | "Second")[] - ( - start: number, - deleteCount?: number | undefined - ): ("First" | "Second")[] - } & string - ]: never - readonly [ - x: (( - index: number, - value: "First" | "Second" - ) => ("First" | "Second")[]) & - string - ]: never - readonly [ - x: (() => IterableIterator<"First" | "Second">) & - string - ]: never - readonly [x: never]: never readonly First: 0 readonly Second: 1 } From b3af1d1ff919e5a3f936194b5cf2835fdd699acd Mon Sep 17 00:00:00 2001 From: Kevin Ingersoll Date: Fri, 20 Sep 2024 04:19:33 -0700 Subject: [PATCH 3/3] Create red-gifts-cheat.md --- .changeset/red-gifts-cheat.md | 5 +++++ 1 file changed, 5 insertions(+) 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`.