How to type either
Quick question. I have an object I'm passing as a parameter. It has the shape
I need either or both id and name, and I require foo. How would I go about typing this?
5 Replies
Does this work?
It does, idk why I didn't think of explicitly unioning the three possible versions
thanks legend
Hmm actually it's not
It's telling me that id and name don't exist on type mything when i use it as a param
hmm this works apparently
thanks for the help you got me 95% of the way there
Can you do
name?: never
and id?: never
to make it even more explicit (I had that before, but removed it since I thought it worked w/o 😓)Would
never
imply it can't be two at once?Yeah you'd have to have the 3rd one saying it can be both