type-fest
type-fest copied to clipboard
Proposal: `Must`
Like Required
make all properties in T required.
I want to propose adding Must
, which makes all properties in T NonNullable.
type Must<T> = {
[P in keyof T]-?: NonNullable<T[P]>;
};
If it makes sense, I can make a PR.
What's the use-case and how does it differ from Required
?
Required
only make the property not optional, but keeping null.
I think that we need a way to strip null
too.
See related discussion here
Ah, that makes sense. I think this could be useful. However, I don't think the name is clear enough.
How about NonNullableDeep
?
Interesting, something that makes the value:
- Required
- Not
null
- Not
undefined
I would suggest StrictlyRequired
, what do you think?
Is this type supossed to nest within object properties? If so, then a Deep
suffix is valid, because thats the naming pattern used throughout the project. Since the type would deeply apply NonNullable
I think NonNullableDeep
is the name that makes the underlying logic obvious.
@kainiedziela You're very right, the Deep
suffix is very valid! Let me change my suggestion to StrictlyRequiredDeep
.
I don't think NonNullableDeep
is the best because it seems to imply that the only thing happening is NonNullable
being applied recursively. I'd even prefer RequiredAndNonNullableDeep
or NonNullableAndRequiredDeep
over NonNullableDeep
, but StrictlyRequiredDeep
seems to fit it well and is shorter.
I didn't think that applying NonNullable
recursively at initial, but it's a good idea too.
So how do you guys think about adding two types:
- A single level NonNullable types, name as
StrictlyRequired
or something else - A recursively
deep
one, name asNonNullableDeep
orStrictlyRequiredDeep
@LucienLee That looks great to me.
need NonNullableDeep, current version is not recursive.