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

Use more permissive type for defineCollection schema option #8163

Merged
merged 4 commits into from
Aug 21, 2023

Conversation

delucis
Copy link
Member

@delucis delucis commented Aug 20, 2023

Changes

  • Makes the type for the schema option in defineCollection more permissive to match what we actually support internally.
  • The current stricter type allows only the following, i.e. objects, unions of objects, or an intersection of objects:
    • z.object({...})
    • z.union([z.object({...}), z.object({...}), ...])
    • z.object({...}).and(z.object({...})
    • z.discriminatedUnion('type', [z.object({...}), z.object({...})])
  • By making the type recursive, it also allows cases such as unions of unions, intersection of an object with an object union etc. If a user provides one of these types today, the code runs as expected, but tsc and editor tooling will complain about a type error.
  • The base type is still only for objects, so this doesn’t expand the type to unsupported shapes like arrays or string literals etc. it just allows different permutations of unions and intersections of objects.

Testing

  • Patched astro in a project and used more complex schema — no type error was shown.
  • Existing tests should pass.

Docs

I don’t think this needs additional docs — basically just updates the type to better match the current behaviour.

@changeset-bot
Copy link

changeset-bot bot commented Aug 20, 2023

🦋 Changeset detected

Latest commit: 82d81b9

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot added the pkg: astro Related to the core `astro` package (scope) label Aug 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg: astro Related to the core `astro` package (scope)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants