Issue
I'm returning data from an API call. The returned JSON looks like this:
{
"data": {
"getAccountDetails": {
"cars": [
{
"rental": true,
"id": "abcdefg"
}
]
}
}
}
I'm trying to console log the boolean rental (true or false). I keep getting this typescript error: ':' expected. ts(1005. This is how I'm console logging:
console.log(data?.getAccountDetails?.cars?[0]);
How can I resolve this error?
Solution
You are missing a dot.
console.log(data?.getThermostatDetails?.thermostats?.[0]);
It's ?. even when you want to access a property via square brackets.
Answered By - Giovanni Londero
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.