Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

How not to provide the keys for "deep" types every time? #76

Closed
ProdigySim opened this issue Dec 16, 2019 · 3 comments
Closed

How not to provide the keys for "deep" types every time? #76

ProdigySim opened this issue Dec 16, 2019 · 3 comments
Labels
question More info is requested wiki It's nice to learn stuff

Comments

@ProdigySim
Copy link

ProdigySim commented Dec 16, 2019

馃崺 Feature Request

Is your feature request related to a problem?

No.

Describe the solution you'd like

type DeepOptional<O extends object, K extends Index = keyof O> = Optional<O, K, 'deep'>'

Using Object.Optional is very handy. But if you want to use the 'deep' option, it requires filling in the optional K parameter as well. For most cases where I want to use a deep-optional object, I'd like to use the default K = 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 write O.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 for Object.Optional<O,K, 'deep'> and functionality is the same.

Examples

declare const mockItem: O.Optional<IItem, keyof IItem, 'deep'>;
// vs
declare const mockItem: O.DeepOptional<IItem>;
@millsp
Copy link
Owner

millsp commented Dec 16, 2019

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?

@millsp millsp added the question More info is requested label Dec 16, 2019
@ProdigySim
Copy link
Author

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 any workaround does remove a lot of the need.

@millsp millsp changed the title Alias for "DeepOptional" How not to provide the keys for "deep" types every time? Dec 17, 2019
@millsp
Copy link
Owner

millsp commented Dec 17, 2019

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 any is short enough not to create a new alias.

Cheers

@millsp millsp closed this as completed Dec 17, 2019
@millsp millsp added the wiki It's nice to learn stuff label Dec 17, 2019
Repository owner locked and limited conversation to collaborators Feb 2, 2021

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
question More info is requested wiki It's nice to learn stuff
Projects
None yet
Development

No branches or pull requests

2 participants