Typescript error TS2339: property 'webkitURL' does not exist in type 'Window'

Using Angular 2 in a project that is compiled using typescript.

Getting this error while trying to create a blob image:

error TS2339: Property 'webkitURL' does not exist on type 'Window'

Ts code:

public url = window.URL || window.webkitURL; this.photo = this.url.createObjectURL( res );

+7
javascript google-chrome angular typescript webkit
source share
4 answers

error TS2339: property 'webkitURL' does not exist in type 'Window'

lib.d.ts does not come with browser-specific data. However, you can easily do (window as any).webkitURL . This is called a type statement .

More details

A general style type statement (as any) is quickfix provided by alm: https://basarat.gitbooks.io/alm/content/features/quickfix.html

+14
source share

Solution that works with TypeScript 2.1.5:

 interface Window { webkitURL?: any; } declare var window: Window; if (window.webkitURL !== undefined) { console.log(window.webkitURL); } 

In the above code, we declared an interface / form for the window that will have the webkitURL option, and then we will check the validation to make sure it is defined.

+1
source share

This approach worked for me. My current typescript version is 2.0.3

add this from class

  interface Window { logged_user: Object } 

and when you need to use this property just use it

 window.logged_user = {};//your data 
-one
source share

Solution 1:

 interface Window { webkitURL: any; } declare var window: Window; //Now typescript will not throw any error on window.webkitURL 

Solution 2: (<any>window).webkitURL does not cause ts error

-2
source share

All Articles