I am getting a error and I don't fully understand why. I understand that it could be undefined and therefore I need to check if it exists but if I setup the code as below then I get the errors. However if I replace {showDescription && with {isFeatureBlock && description && inline it works perfectly. Why does it not work if I assign it to a const?
Note: I have simplified to focus on the main issue.
The Code
isFeatureBlock is a boolean, description is optional string
const showDescription = isFeatureBlock && description
{showDescription && (
<BlockDescription>
{description}
</BlockDescription>
)}
The Error
- 'Argument of type 'string | undefined' is not assignable to parameter of type 'string'. Type 'undefined' is not assignable to type 'string'
{showDescription && ( <BlockDescription> {description} </BlockDescription> )}? Is it object or something else?