how can i add adsbygoogle adsense property to the global window object in typescript?

The following article helped my to find a solution to this:

https://mariusschulz.com/blog/declaring-global-variables-in-typescript

AMBIENT.d.ts

interface Window {
  adsbygoogle: {[key: string]: unknown}[]
}

From that article:

Augmenting the Window Interface

Lastly, you can use TypeScript’s interface declaration merging to let the compiler know that it can expect to find a property named INITIAL_DATA on the Window type and therefore the window object. To do that, you’ll need to define an interface named Window with a property named INITIAL_DATA:

enter image description here

TypeScript will merge this interface definition together with the Window interface defined in lib.dom.d.ts, resulting in a single Window type. Now, the following assignment will no longer produce a type error:

enter image description here

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top