lib.d.ts doesn't have a definition for window.opera and is read-only, what do?

Topics: General
Nov 20, 2012 at 2:00 AM

window.opera is a common way for checking if the browser is using opera.  But when I use this in typescript it complains that "The property 'opera' does not exist on the value of type 'Window'.


How do I go about adding the opera object to window?

Nov 20, 2012 at 3:43 PM

You can extend an interface by declaring it multiple times.  For your example,  you could do so using:

interface Window {
  opera: any;

Unfortunately, there's a current limitation that you can't extend interfaces in lib.d.ts.  This is will be fixed in a future version.

Nov 20, 2012 at 11:10 PM

One of my work buddies figured it out for me.. Its a temporary solution.. but you can just do:




and that gets around the compile time error.

Nov 21, 2012 at 2:45 PM

Thanks for the tip!

Nov 27, 2012 at 7:04 PM

You can also do (<any>window).opera