Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

Using Angular 2 on a project which is compiled with typescript.

Getting this error when trying to create a blob image:

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

ts code is:

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

like image 547
Dan Reil Avatar asked Aug 06 '16 08:08

Dan Reil


People also ask

How do you fix property does not exist on type?

The "Property does not exist on type '{}'" error occurs when we try to access or set a property that is not contained in the object's type. To solve the error, type the object properties explicitly or use a type with variable key names.

Does not exist on type window typescript?

The "Property does not exist on type 'Window & typeof globalThis'" error occurs when we access a property that does not exist in the Window interface. To solve the error, extend the Window interface in a . d. ts file adding the property you intend to access on the window object.


1 Answers

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

The lib.d.ts does not ship with stuff that is browser specific. However you can easily do (window as any).webkitURL. This is called a type assertion.

More

  • docs on lib.d.ts
  • Quick migration tips

The common (as any) style type assertion is a quickfix provided by alm : https://basarat.gitbooks.io/alm/content/features/quickfix.html

like image 78
basarat Avatar answered Sep 26 '22 13:09

basarat