user3423927
user3423927

Reputation: 61

Why this JavaScript code fails in TypeScript?

I found below JavaScript code snippet in adsense's developers.google.com site which allows me to inject external JS file into an iFrame when added few other parameters.

    (function(g,o){g[o]=g[o]||function(){(g[o]['q']=g[o]['q']||[]).push(
  arguments)},g[o]['t']=1*new Date})(window,'_googCsa');

When I tried to use above snippet in a Typescript file it gives me an error(shown in the picture down below). I tried fixing it but nothing was successful. enter image description here

Please help me fix this code snippet. I would like to use that snippet in an angular app component.

Upvotes: 1

Views: 110

Answers (1)

recursive
recursive

Reputation: 86144

Typescript has a problem with using multiplication on a date. In this code, multiplication is being used to implicitly coerce the Date to a number. However, you can just accomplish the same thing explicitly.

(new Date).valueOf()

Upvotes: 1

Related Questions