I have two props showAccountName and accountType.
accountType is required only when showAccountName is true. When showAccountName is false, accountType is not required.
So, I used a type union -
type AccountProps =
| { showAccountName?: false; accountType: never; }
| { showAccountName?: true; accountType: string; }
and trying to extend these props in a class component
class UserAccount extends React.PureComponent<AccountProps>
{ .... }
But I am unable to access showAccountName or accountType using this.props in UserAccount. Any idea what I am doing wrong here? Or is there any other way to make one prop mandatory based on another optional prop? (without using type)
I am new to typescript, any help is much appreciated!