1

I have type Action = {actionText: string, onClick: VoidFunction}

and I want to use it, optionally, inside MyComponent props so MyComponent can have an action (and then it must get both actionText and onClick props) or it may not have an action (and then it doesn't get any of them)

so the result will be something like: type MyComponentType = {title: string} & [optional]Action

what is the best way to do it?

GO VEGAN
  • 1,113
  • 3
  • 15
  • 44
  • 1
    [Here](https://tsplay.dev/mZ4nJw) you have a working eample. See [this](https://stackoverflow.com/questions/65805600/type-union-not-checking-for-excess-properties#answer-65805753) answer for more context – captain-yossarian from Ukraine Jun 06 '22 at 10:24
  • it works, thanks! but, can you explain why all this code is necessary and not just `type OptionalIntersection = T | (T & O);` – GO VEGAN Jun 12 '22 at 08:41
  • 1
    Because `Partial&T` will be assignable to `T`. From what I understood, you want either `T` or `T & O` but not partial solution.v TypeScript is structural typed language. – captain-yossarian from Ukraine Jun 12 '22 at 11:54

0 Answers0