I'm trying to create a type to express the following constraint:
// Valid
{
"foo": "foo"
}
// Valid
{
"bar": "bar"
}
// Not valid
{
"foo": "bar"
}
I think I should be able to do this with mapped types:
type KeyValueSameDict = {
[key in string]: key
};
However, this simply infers the type Record<string, string>. I also think I could do this if I knew the keys ahead of time:
type KeyValueSameDictKeys = "foo" | "bar";
type KeyValueSameDict = {
[v in KeyValueSameDictKeys]?: v;
};
However, I would like a way to not have to do that.
Is what I'm trying to do possible?