I am currently working with Typescript version 3.9.x
Let's say I have the following interface:
interface mytype {
foo: Foo
bar: Bar
baz: Baz
}
I aim to create a OnlyOneOfType<T>
type that allows only one member within the interface.
For example:
const test1: OnlyOneOfType<mytype> = {foo: 'FOO'}; // Should be valid
const test2: OnlyOneOfType<mytype> = {bar: 'BAR'}; // Should be valid
const test3: OnlyOneOfType<mytype> = {foo: 'FOO', bar: 'BAR'}; // Should fail