DEV Community

Discussion on: Optional booleans?

Collapse
 
lexlohr profile image
Alex Lohr

Consider this more modern TS example:

const whatever = ({ darkMode = false, ...rest }) => null

It is not three different values, but a boolean value with a default so it can be optional.

If this was a component, every user would be forced to declare the darkMode property like it or not if it was not optional, which to me makes no sense if you can have a default.