Skip to content

Optimize extendShape #4150

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

Merged
merged 1 commit into from
Apr 16, 2025
Merged

Optimize extendShape #4150

merged 1 commit into from
Apr 16, 2025

Conversation

Andarist
Copy link
Contributor

@Andarist Andarist commented Apr 14, 2025

It has been proposed here and, in fact, it cuts AnswerOverflow/apps/dashboard's instantiations from 13672403 to 3538464 (74% reduction) and check time from 6.5s to 4s (38% reduction).

Summary by CodeRabbit

  • Refactor
    • Improved the efficiency of type-level merging for object shapes, resulting in faster and more direct merging when object keys do not overlap. This change affects only type definitions and does not impact runtime behavior.

Copy link
Contributor

coderabbitai bot commented Apr 14, 2025

Walkthrough

The changes update two TypeScript utility types, MergeShapes and extendShape, within the objectUtil namespace. Both types now include a conditional check to determine if the key sets of the objects being merged overlap. If there are no overlapping keys, the types are combined using a simple intersection; if there are overlapping keys, the merge uses the original exclusion-based logic. These modifications affect only the type-level behavior and do not alter any runtime code.

Changes

File(s) Change Summary
deno/lib/helpers/util.ts, src/helpers/util.ts Updated MergeShapes and extendShape types in the objectUtil namespace to include a conditional fast path for merging.

Poem

In the warren of types where the helpers reside,
Two shapes now merge with a swifter stride.
If keys don’t collide, they simply unite,
But if there’s a clash, they merge as they might.
Type rabbits rejoice—less hopping around!
For merging is faster when overlaps aren’t found.
🐇✨

Tip

⚡💬 Agentic Chat (Pro Plan, General Availability)
  • We're introducing multi-step agentic chat in review comments and issue comments, within and outside of PR's. This feature enhances review and issue discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments and add commits to existing pull requests.

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e6017b0 and 6a4fdfc.

📒 Files selected for processing (2)
  • deno/lib/helpers/util.ts (2 hunks)
  • src/helpers/util.ts (2 hunks)
🔇 Additional comments (4)
src/helpers/util.ts (2)

100-106: Excellent performance optimization for MergeShapes type!

This optimization introduces a fast path for merging object types when there are no overlapping keys. By using a direct intersection (U & V) in cases where keys don't overlap, the TypeScript compiler can avoid the more complex exclusion-based merging, significantly reducing type instantiations. This aligns with the PR objectives, which report a 74% reduction in instantiations and 38% improvement in type checking time.


138-146: Well-implemented optimization for extendShape type utility

Similar to the MergeShapes optimization, this adds a fast path for cases where object keys don't overlap. The implementation is correct and maintains the same semantics - if keys overlap, it falls back to the original exclusion-based logic. When keys don't overlap, using a simple intersection (A & B) is more efficient and produces equivalent results.

The comment explaining the optimization is clear and helpful for future maintainers.

deno/lib/helpers/util.ts (2)

100-106: Excellent performance optimization for MergeShapes type!

This optimization introduces a fast path for merging object types when there are no overlapping keys. By using a direct intersection (U & V) in cases where keys don't overlap, the TypeScript compiler can avoid the more complex exclusion-based merging, significantly reducing type instantiations.

The changes are identical to those in src/helpers/util.ts, maintaining consistency across the codebase.


138-146: Well-implemented optimization for extendShape type utility

This optimization mirrors the one applied to MergeShapes, creating a fast path for object type merging when keys don't overlap. The implementation is correct and preserves the original behavior while improving performance.

The consistent approach between this file and src/helpers/util.ts ensures unified behavior across different parts of the codebase.

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

netlify bot commented Apr 14, 2025

Deploy Preview for guileless-rolypoly-866f8a ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 6a4fdfc
🔍 Latest deploy log https://app.netlify.com/sites/guileless-rolypoly-866f8a/deploys/67fe214f7ec72c0008a3f048
😎 Deploy Preview https://deploy-preview-4150--guileless-rolypoly-866f8a.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@samchungy
Copy link
Contributor

It has been proposed here and, in fact, it cuts AnswerOverflow/apps/dashboard's instantiations from 13672403 to 3538464 (74% reduction) and check time from 6.5s to 4s (38% reduction).

Summary by CodeRabbit

  • Documentation

    • Added "fullproduct.dev" to the "Powered by Zod" section in the README.
  • Refactor

    • Improved type-level merging logic for utility types, optimizing for cases where object keys do not overlap. No impact on runtime behavior.

btw @Andarist, I think this may have already been optimised in Zod 4:
https://v4.zod.dev/v4
#4074

Co-authored-by: Anders Hejlsberg <andersh@microsoft.com>
@Andarist
Copy link
Contributor Author

Given how popular v3 is, I think it still would be good to backport this but, of course, it's up to @colinhacks

@colinhacks
Copy link
Owner

Just when I thought I'd tried every conceivable implementation of ExtendShape Anders drops this fast-path approach. Glorious.

@colinhacks colinhacks merged commit 3e602d4 into colinhacks:main Apr 16, 2025
9 of 10 checks passed
@colinhacks
Copy link
Owner

colinhacks commented Apr 16, 2025

Benchmarks. This builds the somewhat adversarial script in this gist — a chain of .omit() and .extend() calls. I chained as many calls as possible before TS threw an Excessively Deep error, so basically this benchmark is designed to be as impressive as possible 🤷‍♂️ And it is :)

Metric Zod 3.24.2 (Pre-change) Zod 3.24.3 (Post-change) Factor
Total Time 3.15s 0.50s 6.3× faster
Check Time 2.15s 0.15s 14.3× faster
Emit Time 0.69s 0.03s 23.0× faster
Transform Time 0.68s 0.02s 34.0× faster
Instantiations 15,415,384 165,263 98.9% reduction

Zod 3.24.2 (pre-change)

$ pnpm run build:bench

> @zod/tsc-perftest@1.0.0 build:bench /Users/colinmcd94/Documents/projects/zod/packages/tsc
> tsc -p tsconfig.bench.json

Files:                          162
Lines of Library:             39498
Lines of Definitions:         54853
Lines of TypeScript:            107
Lines of JavaScript:              0
Lines of JSON:                    0
Lines of Other:                   0
Identifiers:                  87917
Symbols:                      82218
Types:                         9900
Instantiations:            15415384
Memory used:                119682K
Assignability cache size:      2548
Identity cache size:              6
Subtype cache size:               0
Strict subtype cache size:        0
I/O Read time:                0.01s
Parse time:                   0.16s
ResolveModule time:           0.02s
ResolveTypeReference time:    0.00s
ResolveLibrary time:          0.01s
Program time:                 0.23s
Bind time:                    0.08s
Check time:                   2.15s
transformTime time:           0.68s
commentTime time:             0.00s
I/O Write time:               0.00s
printTime time:               0.69s
Emit time:                    0.69s
Total time:                   3.15s

Zod 3.24.3 (post-change)

$ pnpm run build:bench
> @zod/tsc-perftest@1.0.0 build:bench /Users/colinmcd94/Documents/projects/zod/packages/tsc
> tsc -p tsconfig.bench.json

Files:                         163
Lines of Library:            39498
Lines of Definitions:        54891
Lines of TypeScript:           107
Lines of JavaScript:             0
Lines of JSON:                   0
Lines of Other:                  0
Identifiers:                 87903
Symbols:                     83156
Types:                       10054
Instantiations:             165263
Memory used:               122090K
Assignability cache size:     2673
Identity cache size:             6
Subtype cache size:              0
Strict subtype cache size:       0
I/O Read time:               0.02s
Parse time:                  0.16s
ResolveModule time:          0.02s
ResolveTypeReference time:   0.00s
ResolveLibrary time:         0.01s
Program time:                0.24s
Bind time:                   0.08s
Check time:                  0.15s
transformTime time:          0.02s
commentTime time:            0.00s
I/O Write time:              0.00s
printTime time:              0.03s
Emit time:                   0.03s
Total time:                  0.50s

@jakebailey
Copy link

How did emit time end up shrinking?

@Andarist
Copy link
Contributor Author

@jakebailey serializeTypeForDeclaration can lead to instantiateType calls - and I've verified that this particular emit involves many of those. So given the instantiations were reduced by a large margin - the emit time could also easily go down here.

@Andarist
Copy link
Contributor Author

This builds the somewhat adversarial script in this gist — a chain of .omit() and .extend() calls

I thought this would still perform poorly but it doesnt 🤔

@Andarist Andarist deleted the perf/extendShape branch April 17, 2025 12:46
@Shakeskeyboarde
Copy link

Shakeskeyboarde commented May 2, 2025

@colinhacks If I update Zod from 3.24.2 to 3.24.3 in this project, I get out of memory errors when running the build script (specifically, the tsc command in the build script). While the performance improvements here look amazing, I think the hack used to get them may cause some real world issues.

@samchungy
Copy link
Contributor

samchungy commented May 2, 2025

@colinhacks If I update Zod from 3.24.2 to 3.24.3 in this project, I get out of memory errors when running the build script (specifically, the tsc command in the build script). While the performance improvements here look amazing, I think the hack used to get them may cause some real world issues.

I can see in your lockfile that you could have multiple versions of zod which will often cause these issues. Make sure they're all the same

@Shakeskeyboarde
Copy link

Shakeskeyboarde commented May 2, 2025

@colinhacks If I update Zod from 3.24.2 to 3.24.3 in this project, I get out of memory errors when running the build script (specifically, the tsc command in the build script). While the performance improvements here look amazing, I think the hack used to get them may cause some real world issues.

I can see in your lockfile that you could have multiple versions of zod which will often cause these issues. Make sure they're all the same

Where are you seeing multiple versions? I see only 3.24.2 everywhere. There are some transitive ranges that have a lower range bound. But it's all resolving to 3.24.2.

Edit: Tried again. Made sure there was only one version of Zod. Couldn't reproduce. So, I must have done something wrong or missed a step the first time. I retract my comment. 3.24.3 works as long as there is only one Zod version.

colinhacks added a commit that referenced this pull request May 19, 2025
* feat(lang): Added initial Azerbaijani locale (#4158)

* feat(lang): Added initial Azerbaijani locale

* Format

---------

Co-authored-by: Colin McDonnell <colinmcd94@gmail.com>

* fix(docs): Typo fro (#4157)

* Fix broken logo link (#3974)

* Fix broken logo link

* Use absolute URL

* Absolute url

---------

Co-authored-by: Colin McDonnell <colinmcd94@gmail.com>

* Add packages/docs

* Remove packages/docs

* Clean up zodmini exports with underscores

* Add precommit format

* Fix error generic

* Fix optionality docs

* tweak (#4173)

Co-authored-by: Colin McDonnell <colinmcd94@gmail.com>

* fix: dev:play script to use play.ts instead of playground.ts (#4177)

* Optimize `extendShape` (#4150)

Co-authored-by: Anders Hejlsberg <andersh@microsoft.com>

* 3.24.3

* add back packages/docs

* Update

* Update benchmark

* Refactor `Extend` to preserve declaration links (#4155)

* Refactor `ExtendShape` to preserve declaration links

* fix type issues

* Simplify aliases

* Fix lint

* Fix

* Update benchmarks

---------

Co-authored-by: Colin McDonnell <colinmcd94@gmail.com>

* Fix en.ts

* 0.5.2

* 0.6.0

* Fix enum type portability

* Clean up passthrough schemas in toJSONSchema

* 0.6.3

* v4: fix typos in basics guide (#4211)

- Removed redundant whitespaces before `string()` method
- Fixed typo in the note to `.parse()` method

* v4: fix typo in defining schemas section (#4219)

* fix migration guide typos (#4205)

* partial record

* Clean up toJSONSchema behavior. extract schemas with ids

* Improve core.mdx

* Fix missing methods

* 0.7.0

* Fix unrepresentable literals and onattach issues

* 0.8.0

* Improve error customization docs

* Clarify error docs

* Closes #4089

* Fix starts_with

* docs: add zod-schema-faker to ecosystem (#4247)

* fix(docs): Correct "with with" typo. (#4243)

Correct "with with" typo.

* fix(docs): Correct typo in Records (#4244)

Correct typo in Records "that as" instead of "that is".

* fix(docs): Typo in `z.object()` vs `z.interface()` (#4241)

Update documentation to clarify that optional properties in
`z.interface()` are defined with a `?` suffix, not a prefix.

* Correcting the default numeric range to be inclusive. (#4224)

* Reusing `Number.MAX_VALUE` for `float64` range (#4222)

* Clarify defaults for `toJsonSchema` options (#4223)

* docs: add GQLoom to ecosystem (#4225)

* fix(docs): Swap Enum `.exclude() / .extract()` code samples. (#4242)

The code samples in `.exclude()` belong to `.extract()` and vice versa.

* fix(docs): Grammatical error in Refinements (#4252)

Correct grammatical error in Refinements

* Improve handling of `.meta()`/`.describe()` in JSON Schema converter (#4255)

* WIP

* Big improvements to meta and describe handling

* WIP

* Lazy disc

* Add cybozu

* 0.9.0

* Feature Stainless

* Edit alt text

* doc: fixed missing comment in migration guide (#4293)

* fix migration guide typo (#4291)

* Add "zod-config" to ecosystem.tsx (v4 support via pre-release) (#4282)

* Update ecosystem.tsx to add "zod-config" with v4 support via RC

* fix(docs): Correct formatting in ecosystem.tsx for "zod-config" entry

---------

Co-authored-by: Alexandre Marques <a.marques@epilot.cloud>

* docs: add support for `kubb` as part of the v4 upgrade (#4260)

* Add methods to string formats (#4296)

* 0.10.0

* Tweak

* Tweak

* z._default

* Correct conditions for error in docs (#4312)

- Make schema a strict object
- Add extra key to induce error described later

* fix vscode debug issue with tsx runtime (#4306)

* Tweak default docs

* correction in documentation (#4303)

(zod example using @zod/mini import)

* WIP

* Make ulid case insensitive

* v0.10.1

* Improve jsdoc

* ULID

* docs: in v4, `strict()` is not deprecated (#4298)

* docs: in v4, `strict()` is not deprecated

* Tweak

---------

Co-authored-by: Colin McDonnell <colinmcd94@gmail.com>

* chore: add `orval` to XtoZod ecosystems in v4 (#4256)

Co-authored-by: Colin McDonnell <colinmcd94@gmail.com>

* Add composable-functions as a library powered by Zod supporting v4 (#4261)

* Add composable-functions as a library powered by Zod supporting v4

* docs: in v4, `strict()` is not deprecated (#4298)

* docs: in v4, `strict()` is not deprecated

* Tweak

---------

Co-authored-by: Colin McDonnell <colinmcd94@gmail.com>

* chore: add `orval` to XtoZod ecosystems in v4 (#4256)

Co-authored-by: Colin McDonnell <colinmcd94@gmail.com>

---------

Co-authored-by: Shodai Suzuki <info@soartec-lab.work>
Co-authored-by: Colin McDonnell <colinmcd94@gmail.com>

* Support recursive types in `z.object()`, drop `z..interface()` (#4271)

* WIP

* WIP

* Add qin

* WIP

* Refactor object-like internals. use optionality in zodinterface shape. remove ?-prefixing for defaulted. handle optionals/defaults in json schema

* WIP

* WIP

* Generics are working

* WIP

* WIP

* Fix

* Fix tests

* Fix tests

* WIP

* WIP

* Drop `z.interface()` from docs (#4316)

* Drop interface

* Format

* Feature

* Allow HH:MM format in `z.string().datetime()` and `z.string().time()` (#4315)

* feat: allow omitting seconds in time string

* docs: include examples of omitted seconds

* docs: remove whitespace

* 3.23.4

* V4(fix): generate json-schema with min/max(0) (#4267)

* fix: generate number json schema

* fix: generate json schema with min/max(0)

* Apply suggestions from code review

fix: format

Co-authored-by: Anna Bocharova <robin_tail@me.com>

---------

Co-authored-by: Panda <panda@mail.ru>
Co-authored-by: Anna Bocharova <robin_tail@me.com>

* 0.11.1

* docs: added @regle/schemas to form ecosystem (#4169)

* docs: added @regle/schemas to form ecosystem

In my previous MR you said to edit `components/ecosystem.mdx` but couldn't find it, if it was a typo i guessed it was this file! 👍

* Add to ecosystem.tsx

---------

Co-authored-by: Colin McDonnell <colinmcd94@gmail.com>

* Fix union inferred type issue

* v0.11.2

* optionalObjectKeys -> optionalKeys

* 0.11.3

* Add test for union types

* Fix assignability

* 0.11.4

* Add assignability tests

* Stack trace in parse and parseAsync

* Biome

* Clean up code, fix lock

* Document default changes

* Clarify deprecations

* Update changelog

* v0.11.6. support recursive types in zodmini

* Add recursive type tests for zod mini

* Add recursive tests for zod mini

* fix(core): use `Object.create(null)` to cache ids (#4359)

* Jazz sponsorship

* Update Speakeasy sponsor URL (#4337)

* fix: use input, not output, for input of ZodUnionInternals (#4330)

* Languages: Add Japanese language (#4170)

* Add Japanese locale

* format

* fix(ja): Fixed comparison operator in error messages

* Tweak

---------

Co-authored-by: Colin McDonnell <colinmcd94@gmail.com>

* New parse signature

* Fix parse functions

* Add Jazz

* Languages: Add Portuguese language (#4171)

* Adding portuguese translations

* Adding portuguese

* Adding language to docs

* Adding spanish language in docs

* Tweak

* Updating references from string to texto

* Updating faixa to faixa de

* Updating from elementos to itens

* Mirroring validation from original file

* Updating regex to padrao

* Updating entrada by tipo

* Replacing entrada by campo

---------

Co-authored-by: Helmer <11061182+helmerdavila@users.noreply.github.com>
Co-authored-by: Colin McDonnell <colinmcd94@gmail.com>

* Languages: Add french language (#4172)

* Adding french and exporting it

* Adding french in docs

* Update fr.ts

Co-authored-by: Florian Lefebvre <contact@florian-lefebvre.dev>

* Translating datetime

* Tweak

* Update elements

* Update packages/core/src/locales/fr.ts

Co-authored-by: Fabrice Cipolla <fabricecipolla@gmail.com>

---------

Co-authored-by: Helmer <11061182+helmerdavila@users.noreply.github.com>
Co-authored-by: Florian Lefebvre <contact@florian-lefebvre.dev>
Co-authored-by: Colin McDonnell <colinmcd94@gmail.com>
Co-authored-by: Fabrice Cipolla <fabricecipolla@gmail.com>

* Languages: Add Arabic language (#4176)

* feat(lang): Add Arabic locale support

* Update packages/core/src/locales/ar.ts

Co-authored-by: Abdullah Mohammed <554032+abodacs@users.noreply.github.com>

* Update packages/core/src/locales/ar.ts

Co-authored-by: Abdullah Mohammed <554032+abodacs@users.noreply.github.com>

* Update packages/core/src/locales/ar.ts

Co-authored-by: Abdullah Mohammed <554032+abodacs@users.noreply.github.com>

* Update packages/core/src/locales/ar.ts

Co-authored-by: Abdullah Mohammed <554032+abodacs@users.noreply.github.com>

* Update packages/core/src/locales/ar.ts

Co-authored-by: Abdullah Mohammed <554032+abodacs@users.noreply.github.com>

* Update packages/core/src/locales/ar.ts

Co-authored-by: Abdullah Mohammed <554032+abodacs@users.noreply.github.com>

* Update packages/core/src/locales/ar.ts

Co-authored-by: Abdullah Mohammed <554032+abodacs@users.noreply.github.com>

* Update packages/core/src/locales/ar.ts

Co-authored-by: Abdullah Mohammed <554032+abodacs@users.noreply.github.com>

* remove period

* fix: add space after comparison operator

* feat(lang): Add Arabic locale support

* Update packages/core/src/locales/ar.ts

Co-authored-by: Abdullah Mohammed <554032+abodacs@users.noreply.github.com>

* Update packages/core/src/locales/ar.ts

Co-authored-by: Abdullah Mohammed <554032+abodacs@users.noreply.github.com>

* Update packages/core/src/locales/ar.ts

Co-authored-by: Abdullah Mohammed <554032+abodacs@users.noreply.github.com>

* Update packages/core/src/locales/ar.ts

Co-authored-by: Abdullah Mohammed <554032+abodacs@users.noreply.github.com>

* Update packages/core/src/locales/ar.ts

Co-authored-by: Abdullah Mohammed <554032+abodacs@users.noreply.github.com>

* Update packages/core/src/locales/ar.ts

Co-authored-by: Abdullah Mohammed <554032+abodacs@users.noreply.github.com>

* Update packages/core/src/locales/ar.ts

Co-authored-by: Abdullah Mohammed <554032+abodacs@users.noreply.github.com>

* Update packages/core/src/locales/ar.ts

Co-authored-by: Abdullah Mohammed <554032+abodacs@users.noreply.github.com>

* remove period

* fix: add space after comparison operator

* Tweak

* Updated ar.ts with new edits discussed in #4176

* Update packages/core/src/locales/ar.ts

* Update packages/core/src/locales/ar.ts

* Update packages/core/src/locales/ar.ts

* chore: format

* fix: update translation for template_literal

* fix: correct translation for invalid input error message

* fix: spacing in error messages

* fix: show correct prefix

* fix: remove unused template literal

* Update error-customization.mdx

---------

Co-authored-by: Abdullah Mohammed <554032+abodacs@users.noreply.github.com>
Co-authored-by: Colin McDonnell <colinmcd94@gmail.com>
Co-authored-by: Hosam Hamdy <hosam5553@gmail.com>

* Languages: Add Hebrew language (#4183)

* Create he.ts

* Update locales.ts

* Update error-customization.mdx

* Tweak

---------

Co-authored-by: Colin McDonnell <colinmcd94@gmail.com>

* Languages: add Polish 🇵🇱 language (#4184)

* Languages: add polish language

* Fix: apply formatting

* Tweak

* Fix: add missing fallbacks

* Update packages/core/src/locales/pl.ts

Co-authored-by: Marcel <51132547+marceleq27@users.noreply.github.com>

* Update packages/core/src/locales/pl.ts

Co-authored-by: Marcel <51132547+marceleq27@users.noreply.github.com>

---------

Co-authored-by: Colin McDonnell <colinmcd94@gmail.com>
Co-authored-by: Marcel <51132547+marceleq27@users.noreply.github.com>

* Languages: add Ukrainian language (#4185)

* locale: add ukrainian language

* Tweak

---------

Co-authored-by: Colin McDonnell <colinmcd94@gmail.com>

* Languages: add Finnish language (#4188)

* feat: add initial finnish translations

* chore: add export and docs

* Tweak

* feat: add more translations for different data types

* fix: lint errors

* fix: map translation

* feat: only handle used cases in TypeNames

* refactor: pr comments

* refactor: map translation

* refactor: heavily simplify finnish translations

* chore: use unioni instead of yhdiste

Might be more commonly used (gut feeling).

* style: remove unused imports

---------

Co-authored-by: Colin McDonnell <colinmcd94@gmail.com>

* Languages: add Hungarian language (#4186)

* add hungarian

* Tweak

---------

Co-authored-by: Colin McDonnell <colinmcd94@gmail.com>

* Add Simplified Chinese (#4189)

* feat(lang): add Simplified Chinese

* fix: locale

* fix: space format

* Tweak

---------

Co-authored-by: Colin McDonnell <colinmcd94@gmail.com>

* feat(lang): add Vietnamese (vi) locale (#4191)

* feat(lang): add Vietnamese (vi) locale

* Tweak

---------

Co-authored-by: Colin McDonnell <colinmcd94@gmail.com>

* Languages: add Czech language 🇨🇿 (#4192)

* feat: add czech error locales

* fix(locales): improve Czech error messages for clarity

* Fmt

* fix(locales): use correct string error prefix in error message

For Czech language.

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* fix(locales): translate other data types as well

For Czech language.

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* fix(locales): handle nullable variables in error messages

For Czech langauge.

---------

Co-authored-by: Colin McDonnell <colinmcd94@gmail.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* Languages: add italian language (#4194)

* feat: added italian language

* Fmt

* Tweak

---------

Co-authored-by: Colin McDonnell <colinmcd94@gmail.com>

* Languages: add Indonesia language (#4195)

* Languages: add Bahasa Indonesia language

* tweak

* Tweak

* Update packages/core/src/locales/id.ts

Co-authored-by: Griko Nibras <griko@nibras.co>

* Update packages/core/src/locales/id.ts

Co-authored-by: Griko Nibras <griko@nibras.co>

* Update packages/core/src/locales/id.ts

Co-authored-by: Griko Nibras <griko@nibras.co>

* Update packages/core/src/locales/id.ts

Co-authored-by: Griko Nibras <griko@nibras.co>

* Update packages/core/src/locales/id.ts

Co-authored-by: Griko Nibras <griko@nibras.co>

---------

Co-authored-by: Colin McDonnell <colinmcd94@gmail.com>
Co-authored-by: Griko Nibras <griko@nibras.co>

* feat(lang): Added initial Turkish locale (#4196)

* feat(lang): Added initial Turkish locale

* fix(lang): Improve formatting in Turkish error messages

* fix(lang): Update Turkish translations for various terms

* fix(lang): Update Turkish translations for base64 and template literal terms

* fix(lang): Correct Turkish error message for 'starts_with' format

* test(lang): Add unit tests for Turkish locale parsing and validation

* test(lang): Remove console log from Turkish locale test for cleaner output

Co-authored-by: Mert Şişmanoğlu <mertssmnoglu@gmail.com>

* fix(lang): Correct variable reference in Turkish 'starts_with' error message

Co-authored-by: Mert Şişmanoğlu <mertssmnoglu@gmail.com>

---------

Co-authored-by: Mert Şişmanoğlu <mertssmnoglu@gmail.com>
Co-authored-by: Colin McDonnell <colinmcd94@gmail.com>

* feat(locale): add russian language (#4197)

* feat(locale): add russian language

* updates

* feat(locale): add Russian pluralization rules

* fix: tests

* fixes

* fix(locale): correct error message for string format validation in Russian locale

---------

Co-authored-by: Colin McDonnell <colinmcd94@gmail.com>

* feat(locale): add belarusian language (#4199)

* feat(locale): add belarusian language

* feat: add belarusian plurals support

* fix(locale): correct Belarusian error message formatting for string validation

---------

Co-authored-by: Colin McDonnell <colinmcd94@gmail.com>

* feat(lang): Add ota locale in Latin script (#4200)

Co-authored-by: Colin McDonnell <colinmcd94@gmail.com>

* Languages: Add Korean language (#4206)

* chore: run format

* feat(locale): add Korean language

---------

Co-authored-by: Colin McDonnell <colinmcd94@gmail.com>

* Languages: Add Farsi language (#4207)

* feat(lang): add farsi language

* fix: joinValues in invalid_value

---------

Co-authored-by: Colin McDonnell <colinmcd94@gmail.com>

* feat(locale): Add Urdu language (#4208)

* feat(locale): add urdu language

* Fix formatting for ur.ts file

* Fix formatting for ur.ts file

---------

Co-authored-by: Colin McDonnell <colinmcd94@gmail.com>

* Add Macedonian locale support and update documentation (#4214)

Co-authored-by: Antonio Ivanovski <antonio-ivanovski@users.noreply.github.com>
Co-authored-by: Colin McDonnell <colinmcd94@gmail.com>

* Add-fr-ca-locale (#4218)

* chore: Add .pnpm-store to .gitignore

* chore: Add Canadian French locale support

---------

Co-authored-by: Colin McDonnell <colinmcd94@gmail.com>

* feat(locale): add Traditional Chinese (#4226)

* feat(locale): add Traditional Chinese

* fix

---------

Co-authored-by: Colin McDonnell <colinmcd94@gmail.com>

* feat(locale): Add Norwegian (#4229)

* feat: added Norwegian (Bokmål)

* fix: renamed locale to no + improved translations

* fix: forgot to add the file to git...

* fix: more accurate verb for collections

* chore: removed commented out code

* chore: ran linter

* fix: minor tweaks to error messages

* Update packages/core/src/locales/no.ts

I agree, that's better!

Co-authored-by: Steffen Holanger <44159536+spiftire@users.noreply.github.com>

---------

Co-authored-by: Magne Skutle <magne.skutle@lyse.no>
Co-authored-by: Steffen Holanger <44159536+spiftire@users.noreply.github.com>
Co-authored-by: Colin McDonnell <colinmcd94@gmail.com>

* feat(lang): Added initial Thai locale (#4230)

* feat(lang): Added initial Thai locale

* fix(lang): improve thai translation for clarify meaning

---------

Co-authored-by: Colin McDonnell <colinmcd94@gmail.com>

* feat(locale): Add SL locale (#4231)

Co-authored-by: Colin McDonnell <colinmcd94@gmail.com>

* feat(lang): Added initial `Tamil` locale (#4237)

Co-authored-by: Colin McDonnell <colinmcd94@gmail.com>

* Languages: add German language (#4253)

* feat(locales): add Catalan locale support and update documentation (#4287)

Co-authored-by: Colin McDonnell <colinmcd94@gmail.com>

* Languages: Add Malay language (#4204)

* feat(lang): add Malay support

* chore: run format

---------

Co-authored-by: Colin McDonnell <colinmcd94@gmail.com>

* Fix issue issue

* Subclass Error

* Update Error inheritance

* Clean up Error inheritance

* Fix prom test

* Refactor: add subpath imports `zod/v4` (#4364)

* Refactor to subpaths

* Tweak

* Roll back to tshy 1

* Use supershy

* Lint

* drop dryrun

* Add root re-export

* Add file

* Update docs

* Update guide

* Docs and locales barrel file

* Update announcement and changelog

* Update anno

* Add accordion

* Fix readonly issue on zodminienum. Rename _getter to innerType on zodlazy

* Fix diagonal enum issue

* Improve `z.url()`: support `hostname` and `protocol` regexes (#4367)

* Improve z.url(). Add support for hostname and protocol regexes

* Add docs

* Add z.core.$ZodBranded

* Add jitless config flag (#4368)

* Remove util.Exactly from zod-mini masks

* Roll back never toJSONSchema

* Update snaps

* v4: set additionalProperties to false when catchall is never (#4365)

* Document dropping of ctx.path in changelog

* Remove z.core from zod/v4-mini

* Add back z.core

* Document .refine overload drop

* Fix input type for ZodMiniDate

* Add zodpipe mini test

* Clean up params

* Fix test

* docs: escape `.` in the example regex for `z.url` with `hostname` (#4375)

* Document moduleResolution

* typo

* Implement `z.prefault` (#4376)

* WIP

* Implement prefault

* Document prefault

* Add link to function workaround

* Defer initialization to avoid crashes with z.lazy. Closes #4324. (#4377)

* noPrecompilation -> jitless

* Update ZodError section in changelog. Deprecate isOptional and isNullable

* Return data on best-effort basis despite errors

* Fix prefixIssues issue

* Add fallback File interface

* Add back formatError and flattenError functions

* Allow generic on coerce functions (#4379)

* Allow generic on coerce functions

* Clean up

* Add union values test

* Add another lazy schema init test

* Clean up

* Add docs for recursive type debugging.

* Update recursive type docs

* F

* Improve discriminateduion errors (#4384)

* Remove abort property from ZodTransformDef. Add discriminator key to no_discriminator_found issue.

* Clean up

* Clean up Error inheritance

* Remove examples from JSON Schema when io=input

* `z.toJSONSchema`: Defer execution of `override`, improve ref handling (#4385)

* Defer override execution

* Improve refs in json schema. Cleanup.

* Clean up

* Clean up

* Clean up enum input type

* Improve base64 perf. Disallow padding in base64url. (#4386)

* Improve base64 perf. Disallow padding in base64url

* Allow empty base64 string

* Allow empty base64 string

* Clean up

* Document base64url change

* Tweak

* Fix treeify error invalid_union handling

* fix ensure catchValue is applied correctly on validation error (#4382)

* Simplify object generics, add test for empty objects (#4387)

* Simplify object generics. Add tests for empty object types.

* Fix tests

* Fix tests, rename pickomit

* Fix typo in json-schema.mdx (#4380)

* fix: use JSON.stringify to escape toDotPath keys w/ quotes (#4374)

This should also correctly handle even weirder stuff like newlines in proeprty keys. JSON.stringify should do all the right escaping - if it's a valid JSON string, it's a valid key.

Note: one existing test was updated:
```
expect(z.core.toDotPath(["data[0]", "value"])).toMatchInlineSnapshot(`"data[0].value"`); // <- before
expect(z.core.toDotPath(["data[0]", "value"])).toMatchInlineSnapshot(`"["data[0]"].value"`); // <- after
```

This looks correct to me? Previously it was implying a shape of `{data: [{value: '...'}]}` when actually it should be a shape of `{'data[0]': {value: '...'}}` (updated 12:30)

Co-authored-by: Misha Kaletsky <mmkal@users.noreply.github.com>

* Improve min/max in JSON Schema (#4388)

* Add types for bag. Fix setting of min/max in json schema

* Fix minValue/maxValue

* Improve number tests

* Trim

* Remove type on base class

* Fix err

* Mark internals

* Remove partial record accordion

* Update ecosystem

* Add reference to instanceof Class

* Add JSON Schema (#4390)

* Update prefault changelog

* Lazy initialization in union and discunion

* Clean up util

* Fix override execution order

* Add test for override execution order

* Preserve shape key ordering in result (#4396)

* Clean up object parser

* Fix discriminated union

* Add disc union test

* Fix inheritance on ZodDiscriminatedUnion

* Document metadata inheritance

* Metadata inherited across clones (#4401)

* Add back discriminator to `z.discriminatedUnion()` API (#4402)

* WIP

* Add back discriminator, add benchmark

* Update docs

* Play

* Add disc union test, improve docs

* chore: add oRPC to the API Libraries ecosystem (#4349)

oRPC 1.2.0 has full support for Zod 4, from validation to OpenAPI spec generation

Co-authored-by: Colin McDonnell <colinmcd94@gmail.com>

* Update benchmark

* [v3] Allow missing `type` in JWT (#4404)

* WIP

* Improve JWT tests

* Implement pipe optionality. Drop `._zod.optionality` in favor of `._zod.optin` and `._zod.optout`. (#4405)

* Implement pipe optionalty. Switch to optin and optout

* Clean up

* Redirect

* WIP

* Page events

* Move up sponsors

* Try scroller

* Suspense

* No animation

* Add redirects

* Remove logs

* Add Juno (new silver sponsor) (#4408)

* Add Juno (new silver sponsor)

* chore: redo

* chore: redo

* Add redirects

* WIP

* Audit redirects

* Tweak

* v4: Doc updates for release (#4409)

* v4 release updates

* Tweak

* REmove banners

* Add tabs

* Update intro

* Zod 4

* Fix lint

* Simplify readme

* Simplify readme

* Simplify readme

* Simplify readme

---------

Co-authored-by: Chingiz Mammadov <info@chz.dev>
Co-authored-by: Henrikh Kantuni <henrikh.kantuni@gmail.com>
Co-authored-by: Shivam Vijaywargi <vijaywargishivam@gmail.com>
Co-authored-by: Abdalrhman Almarakeby <contact@abdalrhman.me>
Co-authored-by: Mateusz Burzyński <mateuszburzynski@gmail.com>
Co-authored-by: Anders Hejlsberg <andersh@microsoft.com>
Co-authored-by: Andrii Andreichenko <87246480+ShrewdLuni@users.noreply.github.com>
Co-authored-by: Mohammed Alaa Alhaj <82370689+mhdalaa93@users.noreply.github.com>
Co-authored-by: Jonathan Waltz <volcanicislander@gmail.com>
Co-authored-by: Ernest <soc221b.e@gmail.com>
Co-authored-by: Juan Giordana <juangiordana@gmail.com>
Co-authored-by: Anna Bocharova <robin_tail@me.com>
Co-authored-by: xcfox <809067559@qq.com>
Co-authored-by: Shodai Suzuki <info@soartec-lab.work>
Co-authored-by: Dan Michael O. Heggø <danmichaelo@gmail.com>
Co-authored-by: Alexandre Marques <pt.alexandremarques@gmail.com>
Co-authored-by: Alexandre Marques <a.marques@epilot.cloud>
Co-authored-by: Stijn Van Hulle <stijn.vanhulle@pm.me>
Co-authored-by: George Kormaris <mail@gekorm.com>
Co-authored-by: Lakshan Perera <39025880+0xluckycoder@users.noreply.github.com>
Co-authored-by: Kevin Damm <github@kevindamm.com>
Co-authored-by: Guga Guichard <gustavoguichard@gmail.com>
Co-authored-by: Timothy Ng <5664347+timorthi@users.noreply.github.com>
Co-authored-by: Panda <57873412+PandaWorker@users.noreply.github.com>
Co-authored-by: Panda <panda@mail.ru>
Co-authored-by: Victor Garcia <victorgarciaparis13@gmail.com>
Co-authored-by: andrew jarrett <ahrjarrett@gmail.com>
Co-authored-by: Nolan Di Mare Sullivan <nolan.dm.sullivan@gmail.com>
Co-authored-by: Rik Brown <rik@rik.codes>
Co-authored-by: Kio Yoshimatsu <69349613+yoshimatsu567@users.noreply.github.com>
Co-authored-by: Helmer <11061182+helmerdx@users.noreply.github.com>
Co-authored-by: Helmer <11061182+helmerdavila@users.noreply.github.com>
Co-authored-by: Florian Lefebvre <contact@florian-lefebvre.dev>
Co-authored-by: Fabrice Cipolla <fabricecipolla@gmail.com>
Co-authored-by: Abdullah Mohammed <554032+abodacs@users.noreply.github.com>
Co-authored-by: Hosam Hamdy <hosam5553@gmail.com>
Co-authored-by: Shachar Zidon <theonlytails@theonlytails.com>
Co-authored-by: Bartosz Szar <szarbartosz@gmail.com>
Co-authored-by: Marcel <51132547+marceleq27@users.noreply.github.com>
Co-authored-by: Dmytro Dobrovolskyi <1dima9999@gmail.com>
Co-authored-by: Henri Södergård <46006967+Heenkkk@users.noreply.github.com>
Co-authored-by: Lőrik Levente <33373714+Levminer@users.noreply.github.com>
Co-authored-by: GrahamQuan <33834833+GrahamQuan@users.noreply.github.com>
Co-authored-by: Nguyễn Hoàng Trung <trungnh@solashi.com>
Co-authored-by: Filip Ditrich <ditrich@nfctron.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: Davide Lombardi <56124504+berz8@users.noreply.github.com>
Co-authored-by: Krisna Wijaya <krisna.w2010@gmail.com>
Co-authored-by: Griko Nibras <griko@nibras.co>
Co-authored-by: Özgür ÖZALP <ozgurozalp1999@gmail.com>
Co-authored-by: Mert Şişmanoğlu <mertssmnoglu@gmail.com>
Co-authored-by: Vlad Sazonau <16666234+VladSez@users.noreply.github.com>
Co-authored-by: KadimElifba <kadimelifba@gmail.com>
Co-authored-by: Lee Keun Hwee <56650238+Geuni620@users.noreply.github.com>
Co-authored-by: Mojtaba <45169963+Mojtaba-NA@users.noreply.github.com>
Co-authored-by: Asharib Ali <asharibarain4@gmail.com>
Co-authored-by: Antonio <1628876+antonio-ivanovski@users.noreply.github.com>
Co-authored-by: Antonio Ivanovski <antonio-ivanovski@users.noreply.github.com>
Co-authored-by: Sofiane <131229158+sohocine@users.noreply.github.com>
Co-authored-by: Jie Peng <dean.leehom@gmail.com>
Co-authored-by: Magne Skutle <magne.skutle@gmail.com>
Co-authored-by: Magne Skutle <magne.skutle@lyse.no>
Co-authored-by: Steffen Holanger <44159536+spiftire@users.noreply.github.com>
Co-authored-by: Thada Wangthammang <thada.wth@gmail.com>
Co-authored-by: Tadej Polajnar <40028548+TadejPolajnar@users.noreply.github.com>
Co-authored-by: Sasivarnan R <sasivarnan@users.noreply.github.com>
Co-authored-by: Simon Legner <Simon.Legner@gmail.com>
Co-authored-by: Pere Montpeó <pmontp19@users.noreply.github.com>
Co-authored-by: Khairul Haziq <ihaziqkhairi@gmail.com>
Co-authored-by: Jacques <25390037+jecquas@users.noreply.github.com>
Co-authored-by: Loris Sigrist <43482866+LorisSigrist@users.noreply.github.com>
Co-authored-by: chimame <rito.tamata@gmail.com>
Co-authored-by: Fabian Hiller <hillerfabian11@gmail.com>
Co-authored-by: Misha Kaletsky <15040698+mmkal@users.noreply.github.com>
Co-authored-by: Misha Kaletsky <mmkal@users.noreply.github.com>
Co-authored-by: unnoq <contact@unnoq.com>
Co-authored-by: David Dal Busco <david.dalbusco@outlook.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants