From ecf1d4b4429cde7d7d7f7c2624b6e20ad9a8e88e Mon Sep 17 00:00:00 2001 From: ATOM00blue <219721791+ATOM00blue@users.noreply.github.com> Date: Thu, 21 May 2026 08:45:26 +0530 Subject: [PATCH] Support number-keyed records in record() and Describe Broaden record() to accept a number-keyed struct and update the StructSchema inference (via IsRecord) so that Describe> resolves to a record struct schema instead of an object schema. This fixes the TypeScript compile error when typing a number-keyed Record, while leaving string-keyed Record behaviour unchanged. --- src/structs/types.ts | 2 +- src/utils.ts | 4 +++- test/typings/describe.ts | 4 ++++ test/typings/record.ts | 5 +++++ 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/structs/types.ts b/src/structs/types.ts index 3eeb2bf4..6a373170 100644 --- a/src/structs/types.ts +++ b/src/structs/types.ts @@ -364,7 +364,7 @@ export function optional(struct: Struct): Struct { * Like TypeScript's `Record` utility. */ -export function record( +export function record( Key: Struct, Value: Struct ): Struct, null> { diff --git a/src/utils.ts b/src/utils.ts index 5c05d1e1..99e2b1ca 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -242,7 +242,9 @@ export type IsExactMatch = export type IsRecord = T extends object ? string extends keyof T ? T - : never + : number extends keyof T + ? T + : never : never /** * Check if a type is a tuple. diff --git a/test/typings/describe.ts b/test/typings/describe.ts index 643b3774..5d9a7dc8 100644 --- a/test/typings/describe.ts +++ b/test/typings/describe.ts @@ -126,6 +126,10 @@ test>>((x) => { return record(string(), number()) }) +test>>((x) => { + return record(number(), number()) +}) + test>((x) => { return regexp() }) diff --git a/test/typings/record.ts b/test/typings/record.ts index 74180ca2..d52fc2c8 100644 --- a/test/typings/record.ts +++ b/test/typings/record.ts @@ -5,3 +5,8 @@ test>((x) => { assert(x, record(string(), number())) return x }) + +test>((x) => { + assert(x, record(number(), number())) + return x +})