I am trying to check against input file being null in typescript. the problem is that (if condition is erroring out) telling me Object is possibly 'null'. how to check against null for this particular case ?
const input = document.querySelector('#image') as HTMLInputElement;
const loadImage = () =>{
if (input.files[0]['type']) {
const fileType = input?.files![0]['type'];
}
}
<input id="image" ref={inputRef} accept="image/*" type="file" onChange={loadImage} />