Force object to have at least one key ( Object.keys(o).length > 0 )
Force object to have at least one key ( Object.keys(o).length > 0 )
Say I have this object
export interface Name
[key: string]: boolean
const v = <Name>;
how do I prevent this from compiling? What I want to do is force v
to have at least one property:
v
const v = <Name>foo: true;
0
Thanks for contributing an answer to Stack Overflow!
But avoid …
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
But avoid …
To learn more, see our tips on writing great answers.
Required, but never shown
Required, but never shown
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
I don't think it's possible. If you say more about your scenario, we might have more ideas.
– Matt McCutchen
Sep 4 '18 at 21:13