Skip to content

Conversation

@ascorbic
Copy link
Contributor

@ascorbic ascorbic commented Apr 30, 2025

Changes

Previously BaseSchema used recursive type definitions to try to define "any Zod object, or wrapper type that contains objects". This contained self-referencing types that collapsed to any, meaning there was no typechecking for schema defintions. #13706 fixed that by refactoring out the self-references. However this caused Starlight typechecks to fail (and presumably other sites). At its core, this is because Zod types are inherently recursive, so it's impossible to accurately type them without using recursive types, unless you manually define an arbitrary number of depth of reference. There will always be another layer of abstraction that some user (or more likely integration or library) wants to create.

This PR throws it all away, and simply types BaseSchema as ZodType. This is wider than we actually want: it accepts primitives other than objects. However, so does any, so this is an improvement over that.

Fixes #13713

Testing

The Starlight typecheck that was failing in ecosystem-ci is now passing.

Docs

@changeset-bot
Copy link

changeset-bot bot commented Apr 30, 2025

🦋 Changeset detected

Latest commit: d8a979a

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 Apr 30, 2025
@florian-lefebvre
Copy link
Member

I'm not sure it's a good idea to allow any zod type. Pretty sure that will lead to confusion. An alternative maybe is to allow any type but check the schema shape when loading the config

@ascorbic
Copy link
Contributor Author

@florian-lefebvre until yesterday the type was any!

@florian-lefebvre
Copy link
Member

True I forgot 😆

@ascorbic
Copy link
Contributor Author

But I agree that it would to have a runtime check. Also non-trivial, as there's a lot of unwrapping to do and edge cases to handle, so maybe later.

Copy link
Member

@florian-lefebvre florian-lefebvre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better than any for sure!

@ascorbic ascorbic merged commit 30aec73 into main Apr 30, 2025
14 checks passed
@ascorbic ascorbic deleted the loosen-zodtype branch April 30, 2025 15:47
@astrobot-houston astrobot-houston mentioned this pull request Apr 30, 2025
openscript pushed a commit to openscript/astro that referenced this pull request Sep 12, 2025
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.

Content schema errors starting with v5.7.7

2 participants