colinhacks / zod

TypeScript-first schema validation with static type inference
https://zod.dev
MIT License
33.09k stars 1.15k forks source link

fix: adds ` | never` to `objectOutputType` as a signal to the LSP tha… #3580

Open ahrjarrett opened 3 months ago

ahrjarrett commented 3 months ago

This small PR updates the type of objectOutputType to fully evaluate the type.

This only seems to occur with catchall schemas, and only sometimes.

Before:

Screenshot 2024-06-17 at 12 12 45 PM

You can see in the screenshot that the output type includes the type constructor that created it (objectOutputType).

The fix for this when it occurs is to unify the result that objectOutputType returns with never.

The union of any type with the bottom (never) is the first type (| never is an identity operation), so this is a no-op in every context except for the LSP, which interprets a union as a signal that it needs to evaluate the node.

After:

Screenshot 2024-06-17 at 12 14 26 PM
netlify[bot] commented 3 months ago

Deploy Preview for guileless-rolypoly-866f8a ready!

Built without sensitive environment variables

Name Link
Latest commit 4c9de532c526b8222e826f924a4619718f6fef0f
Latest deploy log https://app.netlify.com/sites/guileless-rolypoly-866f8a/deploys/667070873adb430008e5e551
Deploy Preview https://deploy-preview-3580--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.

ahrjarrett commented 2 months ago

@colinhacks any reason not to merge this? Would be great to remove the patch my team is using so we can see the evaluated types for catchall and passthrough schemas.

Before:

Screenshot 2024-07-12 at 12 57 38 PM

After:

Screenshot 2024-07-12 at 12 58 56 PM