question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

All properties are NOT required by default on inferred type

See original GitHub issue

I 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:closed
  • Created 2 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
scotttrinhcommented, Nov 10, 2021

@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. 👍

0reactions
gibbokcommented, Nov 10, 2021

@scotttrinh yes sure, I will write to the other repo. Thanks for your help on this! 😄

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found