I'd like to know if it's possible to extend a type depending on another type's value?
interface NavType {
hideNav?: boolean
dev?: boolean
}
I'd like to allow the use of hideNav only if the dev arg is false.
const Navbar: React.FC<NavType> = ({ children, hideNav, dev = false }) => (
<nav>
{!dev ? (
<NavDefault hideNav={!!hideNav}>{children}</NavDefault>
) : (
<NavDev>{children}</NavDev>
)}
</nav>
)
How can I use conditionals in this case?
// Should PASS
const navArgs1: NavType = {
hideNav: undefined,
dev: true
}
const navArgs2: NavType = {
hideNav: true or false,
dev: false
}
// Should NOT PASS
const navArgs3: NavType = {
hideNav: true or false,
dev: true
}