Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/structs/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ export function optional<T, S>(struct: Struct<T, S>): Struct<T | undefined, S> {
* Like TypeScript's `Record` utility.
*/

export function record<K extends string, V>(
export function record<K extends string | number, V>(
Key: Struct<K>,
Value: Struct<V>
): Struct<Record<K, V>, null> {
Comment on lines +367 to 370
Expand Down
4 changes: 3 additions & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,9 @@ export type IsExactMatch<T, U> =
export type IsRecord<T> = T extends object
? string extends keyof T
? T
: never
: number extends keyof T
? T
: never
: never
Comment on lines 242 to 248
/**
* Check if a type is a tuple.
Expand Down
4 changes: 4 additions & 0 deletions test/typings/describe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ test<Describe<Record<string, number>>>((x) => {
return record(string(), number())
})

test<Describe<Record<number, number>>>((x) => {
return record(number(), number())
})

test<Describe<RegExp>>((x) => {
return regexp()
})
Expand Down
5 changes: 5 additions & 0 deletions test/typings/record.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,8 @@ test<Record<string, number>>((x) => {
assert(x, record(string(), number()))
return x
})

test<Record<number, number>>((x) => {
assert(x, record(number(), number()))
return x
})
Loading