Why do I get a warning here?
Answered
I have two blocks of code which do exactly the same. This one
const plannedJobsFilterCustContacted = $('#plannedJobsFilterCustContacted');
plannedJobsFilterCustContacted.on('change', () =>
{
Settings.set('ep_plannedJobs_filter_custcontacted', plannedJobsFilterCustContacted.val());
PlannedJobs.refreshTable();
});
const showCustContacted = Settings.get('ep_plannedJobs_filter_custcontacted');
if (showCustContacted !== false)
plannedJobsFilterCustContacted.val(Util.htmlDecode(showCustContacted));
gives me no warning, but this one:
const plannedJobsFilterLocked = $('#plannedJobsFilterLocked');
plannedJobsFilterLocked.on('change', () =>
{
Settings.set('ep_plannedJobs_filter_locked', plannedJobsFilterLocked.val());
PlannedJobs.refreshTable();
});
const showLocked = Settings.get('ep_plannedJobs_filter_locked');
if (showLocked !== false)
plannedJobsFilterLocked.val(showLocked);
gives me this warning

in the last row.
Any suggestions?
Please sign in to leave a comment.
Am I right it is JavaScript?
Seems Settings.get can return boolean, and boolean cannot be set as value for plannedJobsFilterLocked
What is Settings.get and what is its return type?
it can return false in case of not existing key and the keys value (which is a string) in case it exists.
You are trying to pass boolean value (showLocked) as an argument for .val() function which requires string/number/string[] in the second example. Hence the warning.
In the first example, you wrap showCustContacted into Util.htmlDecode(), which always returns string. Hence there is no warning