I'm using Typescript 3.9.x
Supposed I have an interface:
interface mytype {
foo: Foo
bar: Bar
baz: Baz
}
I want to achieve a OnlyOneOfType<T>
type that allows only one member within the interface.
Such that:
const test1: OnlyOneOfType<mytype> = {foo: 'FOO'}; // PASSES
const test2: OnlyOneOfType<mytype> = {bar: 'BAR'}; // PASSES
const test3: OnlyOneOfType<mytype> = {foo: 'FOO', bar: 'BAR'}; // fails