Skip to content

When z.infer a Record with Brand as a key, it becomes a Partial Record. #2069

You must be logged in to vote

It seems the problem is caused by this code:

zod/src/types.ts

Lines 3061 to 3069 in 981af65

export type RecordType<K extends string | number | symbol, V> = [
string
] extends [K]
? Record<K, V>
: [number] extends [K]
? Record<K, V>
: [symbol] extends [K]
? Record<K, V>
: Partial<Record<K, V>>;

If it were changed to: [K] extends [string], it might work for you.
However, I'm not sure if that will be a breaking change for other users.

Replies: 5 comments 11 replies

You must be logged in to vote
1 reply
@Hiroshiba

You must be logged in to vote
0 replies

You must be logged in to vote
1 reply
@Hiroshiba

You must be logged in to vote
9 replies
@Hiroshiba

@googol

@EvilAlexei

@googol

@wdanilo

Answer selected by JacobWeisenburger

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
6 participants
Converted from issue

This discussion was converted from issue #2065 on February 19, 2023 20:20.