All properties are NOT required by default on inferred type
See original GitHub issueI am following the README, at this point
https://github.com/colinhacks/zod#objects
an example is provided stating that “all properties are required by default”, but when inspecting the inferred types I see that all properties are optional instead.
Minimal reproducible example (zod v 3.11.6) https://stackblitz.com/edit/react-ts-eihrxu
Hover on line 18 on DogType
I can see the inferred type as:
type DogType = {
name?: string;
age?: number;
}
when instead, accordingly to the doc should be:
type DogType = {
name: string;
age: number;
}
Questions:
- Is the document correct/updated?
- How to make sure the properties are not inferred as optional? If you would provide a working sample I would appreciate it
Thanks for your time and great work on zod!
Issue Analytics
- State:
- Created 2 years ago
- Comments:5
Top Results From Across the Web
Why is the inferred type like this ? - Stack Overflow
Unfortunately, it is unable to infer all the types you need before it stops, and so some of the type positions still have...
Read more >Never might be reasonably inferred to have properties also of ...
default : const reportCopy: any = report; assertImpossible(reportCopy.type);.
Read more >Documentation - Type Inference - TypeScript
This kind of inference takes place when initializing variables and members, setting parameter default values, and determining function return types. In most ...
Read more >Swift Regret: Inferred Property Types // -dealloc
Swift regret: inferred types for globals and stored properties In Swift, as in many other statically-typed languages these days, ...
Read more >Type inference - Kotlin language specification
Local type inference, for inferring types of expressions locally, ... which does not contain any free type variables with no explicit constraints on...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@gibbok no problem! if you get something working, feel free to report back here and we can update the readme to help anyone else who might hit up against this issue. 👍
@scotttrinh yes sure, I will write to the other repo. Thanks for your help on this! 😄