You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
Is there was a way to type an object to require that it has exactly one key? The key itself can be any
string
(ornumber
orsymbol
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 asRecord<string, any>
.Upvote & Fund
The text was updated successfully, but these errors were encountered: