Given the following scenario,
function doSomething({ id, name, onSelect, onUnselect }: TDoSomething) {
if (onSelect) {
// I want `onUnselect` to be defined here
// ...
}
return { id, name }
}
type TDoSomething =
| IDoSomethingWithoutSelect
| IDoSomethingWithSelect
interface IDoSomethingWithoutSelect {
id: string
name: string
}
interface IDoSomethingWithSelect {
id: string
name: string
onSelect: (id: string) => void
onUnselect: (id: string) => void
}
What I want to do is (conceptually?) simple: want to have onUnselect to necessarily be defined if onSelect is. In other words, if I pass onSelect, then this function must expect a onUnselect as well.
(A playground to you can be accessed here.)
Turns out my attempts were failures. I don't know exactly what I should do to hit success.