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

后端 未结 7 736
迷失自我
迷失自我 2020-11-30 09:50

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

7条回答
  •  时光取名叫无心
    2020-11-30 10:04

    The simplest solution is to declare e as any

    e.g

    document.getElementById('customimage').onchange = (e: any) => {
        let files = e.target.files[0];
        ...
    };
    

    But you lose type information. A safer approach might be to declare your own FileEvent type based on https://developer.mozilla.org/en-US/docs/Web/API/FileReader/onload.

提交回复
热议问题