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

Type coming through as optional when using z.infer<> #408

Closed
miketamis opened this issue Apr 22, 2021 · 3 comments
Closed

Type coming through as optional when using z.infer<> #408

miketamis opened this issue Apr 22, 2021 · 3 comments

Comments

@miketamis
Copy link

The types are coming through as optional when z.infered
Screen Shot 2021-04-22 at 9 32 15 PM
Screen Shot 2021-04-22 at 9 32 28 PM

@colelawrence
Copy link
Sponsor

I saw something similar using zod@1.11.13 and typescript@4.2.4 with strictNullChecks: true

We also use project references. When invoking tsc --build the types were correct, so we "restarted typescript server" in VS Code and the peculiar issue went away. I'll report back if I find something reproducible.

@Everspace
Copy link

I am also getting this with zod@3.0.0-alpha.33 and typescript@4.2.3. Restarting the typescript server did not help.

image

However adding "include": ["src/**/*"] made this go away which feels odd.

@colinhacks
Copy link
Owner

If you don't have "strictNullChecks": true is your tsconfig compilerOptions or if (for some reason) you're looking a file that isn't covered by your "include", then TypeScript uses the default tsconfig values, which aren't strict. That's when you'll see unexpected optionals in the inferred types.

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

No branches or pull requests

4 participants