Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

z.record makes all his attributes optional #2320

Closed
Andyloz opened this issue Apr 12, 2023 · 4 comments
Closed

z.record makes all his attributes optional #2320

Andyloz opened this issue Apr 12, 2023 · 4 comments
Labels
stale No activity in last 60 days

Comments

@Andyloz
Copy link

Andyloz commented Apr 12, 2023

Look at this:

imagen

It should warn me about foo being missing, but isn't because z.record produces this: Partial<Record<"foo" | "bar", number>>

Is that intentional because of some reason i don't understand? I read all the docs and I couldn't find anything.

Thank you ❤️

@JacobWeisenburger
Copy link
Collaborator

#2069

@JacobWeisenburger JacobWeisenburger added question Further information is requested move-to-discussions? labels Apr 12, 2023
@Andyloz
Copy link
Author

Andyloz commented Apr 12, 2023

@JacobWeisenburger
Well, I have seen that issue, but i don't touch anything related to z.brand.

I made a little research and I've found:

zod/src/types.ts

Lines 3318 to 3328 in 502384e

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>
: [BRAND<string | number | symbol>] extends [K]
? Record<K, V>
: Partial<Record<K, V>>;

If I remove the Partial, the properties become required as I need.

@JacobWeisenburger JacobWeisenburger removed question Further information is requested move-to-discussions? labels Apr 19, 2023
@stale
Copy link

stale bot commented Jul 18, 2023

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@lunelson
Copy link

I've offered a workaround using z.custom here: #2623 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale No activity in last 60 days
Projects
None yet
Development

No branches or pull requests

3 participants