Skip to content

Allow sub-objects for TypeScript strict object schema#2841

Merged
Marsup merged 3 commits intohapijs:masterfrom
joshkel:object-schema-type
Sep 21, 2022
Merged

Allow sub-objects for TypeScript strict object schema#2841
Marsup merged 3 commits intohapijs:masterfrom
joshkel:object-schema-type

Conversation

@joshkel
Copy link
Contributor

@joshkel joshkel commented Sep 20, 2022

A strict nested object was previously typed as ObjectSchema<StrictSchemaMap<T>>, which meant that Joi expected a Joi schema of a Joi schema of an object (i.e., a schema definition for an object of Joi schema fields) - which doesn't make much sense. Instead, it should require a Joi schema of an object or an object of Joi schema fields.

A strict nested object was previously typed as `ObjectSchema<StrictSchemaMap<T>>`, which meant that Joi expected a Joi schema of a Joi schema of an object (i.e., a schema definition for an object of Joi schema fields) - which doesn't make much sense. Instead, it should require a Joi schema of an object _or_ an object of Joi schema fields.
@joshkel
Copy link
Contributor Author

joshkel commented Sep 20, 2022

Update: I had missed that the bug I ran into was already fixed in #2836. However, I believe this change is still worth incorporating, since it allows child objects to be specified inline. (See my updated test.)

@joshkel joshkel changed the title Fix TypeScript types for strict object schema Allow sub-objects for TypeScript strict object schema Sep 20, 2022
@Marsup Marsup self-assigned this Sep 21, 2022
@Marsup Marsup added the types TypeScript type definitions label Sep 21, 2022
Co-authored-by: Nicolas Morel <nicolas@morel.io>
@Marsup Marsup added this to the 17.6.1 milestone Sep 21, 2022
@Marsup Marsup merged commit fcb43bc into hapijs:master Sep 21, 2022
@joshkel joshkel deleted the object-schema-type branch September 21, 2022 18:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

types TypeScript type definitions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants