Issue
I have the following javascript condition.
var year = '2020'
var month = '05'
//var status = 'pending'
var dateParam = '' + year + '-' + month + '%';
if (status == 'pending' || status == 'completed')
{
var query = "SELECT * FROM activities AS a WHERE DATE(a.start_datetime) LIKE ? AND status = ?;";
var where = [
dateParam,
status
]
}
else {
var query = "SELECT * FROM activities AS a WHERE DATE(a.start_datetime) LIKE ?;";
var where = [
dateParam
]
}
console.log(query)
console.log(where)
While it works fine on a code-snippet, I could not get the warning out of Angular/Ionic with the following error.
Subsequent variable declarations must have the same type. Variable 'where' must be of type 'any[]', but here has type 'string[]'.
What would be the best way to resolve this issue? I tried to experiment by declaring
var where = any[] = []
However, did not work and I may have missed something.
Solution
var year = '2020'
var month = '05'
//var status = 'pending'
var dateParam = '' + year + '-' + month + '%';
var where: any[] = [];
if (status == 'pending' || status == 'completed')
{
var query = "SELECT * FROM activities AS a WHERE DATE(a.start_datetime) LIKE ? AND status = ?;";
where = [
dateParam,
status
]
}
else {
var query = "SELECT * FROM activities AS a WHERE DATE(a.start_datetime) LIKE ?;";
where = [
dateParam
]
}
console.log(query)
console.log(where)
Just answer based on your code, declare and initialize where
variable on the top.
because var has not block scope. and then query
variable. too.
Answered By - shun10114
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.