Skip to content

Conversation

felixmosh
Copy link
Contributor

This PR improves object's types.

Before

  1. regular object - output schema is any
const testSchema = Joi.object({ FOO: 'bar' });

image

  1. with keys - output schema is any
    image

  2. with append - output schema not changed
    image

  3. with rename - no key completion, output schema not changed
    image

  4. with with - no key's completion
    image

  5. with without - no key's completion
    image

After

  1. regular object usage incorporates the object type that was passed
    image
    which means that calling to attempt returns the object type properly
    image

  2. using keys
    without provided object
    image
    extending provided object
    image

  3. with append
    append with null or undefined not changing the original obj
    image
    appending new object keys
    image

  4. with rename - key completion, output schema changed
    image
    image

  5. with with - key completion
    image
    completes the rest of the keys (since .with('foo', 'foo') doesn't make sense)
    image

  6. with without - same as with
    image
    image

closes #2978

@Marsup
Copy link
Collaborator

Marsup commented Aug 27, 2023

Hi,

Thanks for all those PRs, I'm a bit torn on this one though. isStrict has been so far used by many people to ensure the schema contains what the type mandates, while inference is a goal, the other way around is also kind of nice, do you think it would be possible to preserve this?

@felixmosh
Copy link
Contributor Author

This is how zod does that...
It is weird (in my opinion) the need of writing a type manually, and then repeat it within the object it self....

I guess i can add an overload or something.

@Neiz-Kap
Copy link

Is it going to be updated/pushed?

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

Successfully merging this pull request may close these issues.

Types of object are incorrect

3 participants