data icon indicating copy to clipboard operation
data copied to clipboard

Generated nested object types

Open r1chm8 opened this issue 3 years ago • 0 comments

Hello, I'm wondering if types returned by generating data in these two different ways should be the same or not?

Example one

article: {
  metadata: {
    author: nullable(String),
  }
},

the returned type of article.metadata.author is string | null | undefined.

Example Two

article: {
  metadata: oneOf('metadata'),
},
metadata: {
  author: nullable(String),
},

the returned type of article.metadata.author is string | null;

I would expect the types to be the same and I'd also expect the type to be string | null. If undefined was required, maybe a helper such as optional(nullable(String)) could be used to generate it.

r1chm8 avatar Nov 03 '22 16:11 r1chm8