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

Require exactly one key of type string #813

Closed
jakeboone02 opened this issue Feb 7, 2024 · 1 comment · Fixed by #849
Closed

Require exactly one key of type string #813

jakeboone02 opened this issue Feb 7, 2024 · 1 comment · Fixed by #849
Labels
help wanted Extra attention is needed type addition

Comments

@jakeboone02
Copy link

jakeboone02 commented Feb 7, 2024

Is there was a way to type an object to require that it has exactly one key? The key itself can be any string (or number or symbol for that matter), but I'd like to ensure there are at least and at most one non-prototype/inherited property.

The use case is for typing the JavaScript implementation of JsonLogic (npm / DT types). In the runtime code, the "logic" object itself and each nested object must satisfy the condition Object.keys(logic).length === 1 (see code).

I tried RequireExactlyOne<Record<string, any>, string>, but that seems to be effectively the same as Record<string, any>.

Upvote & Fund

  • We're using Polar.sh so you can upvote and help fund this issue.
  • The funding will be given to active contributors.
  • Thank you in advance for helping prioritize & fund our backlog.
Fund with Polar
@sindresorhus
Copy link
Owner

Sounds useful. Not sure whether it's possible though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed type addition
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants