type-fest icon indicating copy to clipboard operation
type-fest copied to clipboard

Proposal: `RequiredDeep`

Open osdiab opened this issue 2 years ago • 3 comments

similar to PartialDeep but the inverse, where all KV pairs are required.

osdiab avatar Sep 27 '21 11:09 osdiab

What's the use-case?

sindresorhus avatar Sep 27 '21 11:09 sindresorhus

In my application I have the concept of an "in progress" form which is stored in one DB table, and then the "completed and finalized" form data which is stored in another DB table. The schemas are expressed as Zod schemas and saved in the database as JSON blobs (since the schema is still in flux and we wanted flexibility).

Some data is nested, some are optional in that in-progress form and some are not, but the thing that's definitely true is that all leaves need to be there in the finalized version of the form data. So it's more ergonomic for me to express that type as a deeply required version of the in-progress form.

There are other ways around it but yeah figured that I'm not the only person who might have some usecase for this kind of type.

osdiab avatar Sep 28 '21 05:09 osdiab

Makes sense. Accepted.

sindresorhus avatar Oct 01 '21 04:10 sindresorhus

If anyone wants to work on this, see the initial attempt and feedback: https://github.com/sindresorhus/type-fest/pull/401

sindresorhus avatar Nov 20 '22 11:11 sindresorhus

https://github.com/ts-essentials/ts-essentials/tree/master/lib/deep-required

moltar avatar Mar 31 '23 12:03 moltar