Let's see we have an union of strings:
type PossibleKeys = 'foo' | 'bar'
And we want a type which checks if an object contains no other keys than the above:
type ValidObject = { [key in PossibleKeys]: any }
This works, but it accepts other keys as well, and it requires all the keys, which can be solved with marking it as optional ?, but still accepts other keys.
What I want is to accept:
{foo: true, bar: true}
{foo: true}
{bar: true}
{}
And do not accept:
{foo: true, bar: true, baz: true}
Basically anything else which is not in the accept example.
Is that possible?