I want to create a type MaxOneProp
where you should only be allowed to specify exactly one property. Possible property names are listed in the Props
type.
type Props = 'a' | 'b' | 'c'
type MaxOneProp = Partial<{ [K in Props]: string }>
// should be valid
const a: MaxOneProp = {
a: "abc"
}
// should not be valid
const b: MaxOneProp = {}
const c: MaxOneProp = {
b: "abc",
c: "abc"
}
My current approach Partial<{ [K in Props]: string }>
does not in any way limit the amount of properties of the object.