How do I fix "Expression expected. ts(1109)" in VSCode?
18,882
The if
statement needs an expression to assert if that block of code should be used.
ex:
if (a = true) {
// do something
} else if (b = true) {
// do something else
}
If you just want to render the Breakfast Not Included
you can just use else
without the if
. Or do make it simpler you could make a ternary:
{
hasBreakfast ? <span>Breakfast Included</span> : <span>Breakfast Not Included</span>;
}
Author by
Thein Htut
Updated on July 16, 2022Comments
-
Thein Htut almost 2 years
I encountered VSCode error "Expression expected. ts(1009)" while opening one of the reactjs file.
do
andif
were highlighted red. But I can run the code in my local development environment and also no problem compiling. I guess this is due to VSCode Editor bug.Other editor like Atom or Sublime Text are fine. I used ternary operation in React to solve it but things get really complicated if there are too many
else if
.<div className='form'> // Form stuffs </div> { do{ if (hasBreakfast) { <span>Breakfast Included</span> } else if { <span>Breakfast Not Included</span> } } }
Is there any methods to solve the warning in VSCode?