Skip to content
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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Something similar to AtLeastOne #128

Open
CMCDragonkai opened this issue May 18, 2020 · 2 comments
Open

Something similar to AtLeastOne #128

CMCDragonkai opened this issue May 18, 2020 · 2 comments

Comments

@CMCDragonkai
Copy link

CMCDragonkai commented May 18, 2020

🚀 Feature request

Something similar to:

type AtLeastOne<T> = { [K in keyof T]: Pick<T, K> }[keyof T]

Which is like partial, but ensures at least one property exists.

@DenisFrezzato
Copy link

What's the benefit of that type alias? It garantees that one property is defined, any of the properties, but without knowing which one. In practice, I don't see any difference between AtLeastOne<T> and Partial<T>, you still have to check if the property you need to deal with exists. Am I missing something?

As a side note, that type alias is not "at least", but "exactly one", because according to that type an object can't have more than one property. "At least one" should be modeled like this:

type AtLeastOne<T> = { [K in keyof T]: Partial<T> & Pick<T, K> }[keyof T]

@CMCDragonkai
Copy link
Author

I use AtLeastOne in my sql update queries. And that type works for me. It enforces at least one and allows more than 1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants