Property 'files' does not exist on type 'EventTarget' error in typescript

Chirag Chaudhari :

I am trying to access the value of the input file from my ionic 2 application but still I'm facing the issue of property files does not exist on type 'EventTarget'. As it is properly working in js but not in typescript. The code is given below:

  document.getElementById("customimage").onchange= function(e?) {
            var files: any = e.target.files[0]; 
              EXIF.getData(e.target.files[0], function() {
                  alert(EXIF.getTag(this,"GPSLatitude"));
              });
          }

Please help me solve this issue as it is not building my ionic 2 application.

Diullei :

The e.target property type depends on the element you are returning on getElementById(...). files is a property of input element: https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement

In this case, the TypeScript compiler doesn't know you are returning an input element and we dont have an Event class specific for this. So, you can create one like the following code:

interface HTMLInputEvent extends Event {
    target: HTMLInputElement & EventTarget;
}

document.getElementById("customimage").onchange = function(e?: HTMLInputEvent) {
    let files: any = e.target.files[0]; 
    //...
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Property 'value' does not exist on type EventTarget in TypeScript

Property 'value' does not exist on type 'EventTarget'

New Typescript 1.8.4 build error: " Build: Property 'result' does not exist on type 'EventTarget'. "

property then does not exist on type void , A typescript error

Property 'dataset' does not exist on type 'EventTarget'

Typescript Error: Property 'files' does not exist on type 'HTMLElement'

Property innerWidth does not exist on type EventTarget

KeyboardEvent: Property 'value' does not exist on type 'EventTarget'

TypeScript Compile Error - Property does not exist on type

Property 'name' does not exist on type 'EventTarget' - React + TypeScript

TypeScript error TS2339: Property 'matches' does not exist on type 'EventTarget'

JSDoc: Property 'value' does not exist on type 'EventTarget'

Typescript error: Property 'remove' does not exist on type 'EventTarget'

Property 'parentElement' does not exist on type 'EventTarget'

Property 'value' does not exist on type 'EventTarget & HTMLSelectElement'

ReactJS/TypeScript - Property 'files' does not exist on type 'HTMLElement' error

Property does not exist on type 'Object' Error with Typescript

Typescript type error property does not exist

Property 'selectionStart' does not exist on type 'EventTarget'

Type error: Property 'currentTime' does not exist on type 'EventTarget & HTMLInputElement'

React with TypeScript - Property 'value' does not exist on type 'EventTarget'

Angular 12. error TS2339: Property 'value' does not exist on type 'EventTarget'

Typescript error in ReactJS - Property does not exist on type

Typescript Unions - "property does not exist on type" error

Typescript - Solid.js <select> onchange event: Property 'value' does not exist on type 'EventTarget'

Property 'innerText' does not exist on type 'EventTarget' --TypeScript

Property 'value' does not exist on type 'EventTarget' in Angular

Property 'complete' does not exist on type 'EventTarget'

Typescript error, Property does not exist on type