0

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!

Botond Béres
  • 16,057
  • 2
  • 37
  • 50

1 Answers1

1

Instead of:

value instanceof moment

Try using isMoment method:

moment.isMoment(value)

See the docs and stackblitz demo.

robert
  • 5,742
  • 7
  • 28
  • 37