Reputation: 16683
I have the following code which worked until now but now value.toISOString()
throws a compiler error. I have upgraded from Angular 7 -> 8 which brought with itself an upgrade to Typescript 3.4.5.
Any idea what is causing this?
import * as moment from 'moment';
...
private getQueryStringParameters(parameters: any) {
if (!parameters) {
return '';
}
let queryString = '?';
// tslint:disable-next-line:forin
for (const key in parameters) {
const value = parameters[key];
if (value !== undefined) {
if (value instanceof Array) {
value.forEach(
item =>
(queryString +=
key + '=' + encodeURIComponent('' + item) + '&')
);
} else if (value instanceof moment) {
queryString +=
key +
'=' +
encodeURIComponent('' + value.toISOString()) +
'&';
} else {
queryString +=
key + '=' + encodeURIComponent('' + value) + '&';
}
}
}
Thanks in advance for any input!
Upvotes: 0
Views: 1612
Reputation: 6152
Instead of:
value instanceof moment
Try using isMoment method:
moment.isMoment(value)
See the docs and stackblitz demo.
Upvotes: 1