I want to define a object only have one specific key,and the key depend on a type, for example:
type keys = 'a' | 'b' | 'c'
// thats ok
obj = {
a: 'string'
}
// no
obj = {
a: 'string',
b: 'string'
}
// no
obj = {
a: 'string',
d: 'string'
}
// no
obj = {
d: 'string'
}
I can only think of one way like:
type MyObject = {
[key in keys]?: string
}
but its just half-measures, so is there a good or perfect way?