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

Proposal: ZodObject.omitIfExists() #2144

Closed
wants to merge 2 commits into from

Commits on Mar 5, 2023

  1. Proposal: ZodObject.omitIfExists()

    I found myself wanting to predefine a set of keys that would always
    be omitted from certain schemas if present. Example scenario:
    
    ```
    const OMIT_AUTOGENERATED = {
      id: true,
      uuid: true,
      createdAt: true,
      updatedAt: true
    }
    
    const someSchema = someSchemaRaw.omit(OMIT_AUTOGENERATED);
    const someSchema2 = someSchema2Raw.omit(OMIT_AUTOGENERATED);
    ```
    
    If there are certain "Raw schemas" (using the above nomenclature)
    that don't have all the properties defined in OMIT_AUTOGENERATED,
    then I can't use it on them.
    
    With something like ZodType.omitIfExists() one could blanket-exclude
    a set of keys from schemas without necessarily requiring them to
    be present in all of them.
    jussisaurio committed Mar 5, 2023
    Configuration menu
    Copy the full SHA
    260a0b9 View commit details
    Browse the repository at this point in the history
  2. Run prettier:fix

    jussisaurio committed Mar 5, 2023
    Configuration menu
    Copy the full SHA
    6d03867 View commit details
    Browse the repository at this point in the history