How not to provide the keys for "deep" types every time? #190
Replies: 4 comments
-
Hi @ProdigySim, This is something that is not well documented, but you can do: type test = O.Optional<IItem, any, 'deep'>; Is that what you were looking for? |
Beta Was this translation helpful? Give feedback.
-
Ah, that's definitely a lot better than having to duplicate the first type parameter. I think an alias could still be nice, but the |
Beta Was this translation helpful? Give feedback.
-
I'm marking this as resolved, as on of my goals is to provide a unified API for the type utilities (no duplicates). I feel like typing Cheers |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
🍩 Feature Request
Is your feature request related to a problem?
No.
Describe the solution you'd like
Using
Object.Optional
is very handy. But if you want to use the'deep'
option, it requires filling in the optionalK
parameter as well. For most cases where I want to use a deep-optional object, I'd like to use the defaultK = keyof T
argument, so it's inconvenient to have to specify this parameter manually. Creating an alias for the'deep'
version of the command would allow people to leverage the nice defaults available.Describe alternatives you've considered
I believe Typescript has discussed a feature where you could use
_
in place of a generic parameter to accept the default value. This would let users writeO.Optional<T, _, 'deep'>
instead. However, I can no longer find the TS issue discussing this feature, so I don't know when or if it is expected to arrive.Additionally, users could just create their own
DeepOptional
alias. But it has been nice to be able to consolidate many type aliases in a standard way under a single library like ts-toolbelt.Teachability, Documentation, Adoption, Migration Strategy
We should be able to copy the documentation for
Object.Optional
, adding a note that this method is an alias forObject.Optional<O,K, 'deep'>
and functionality is the same.Examples
Beta Was this translation helpful? Give feedback.
All reactions