Below is my typescript code snippet:
const form = document.querySelector('form');
if (form != null ) {
const data = new FormData(form);
for (const pair of data) {
console.log(pair);
}
// OR
for (const pair of data.entries()) {
console.log(pair);
}
}
document.getElementById("form_file")!.onchange= function(e: Event) {
let file = (<HTMLInputElement>e.target).files[0];
}
I have attempted the following:
let file = (<HTMLInputElement>e?.target)?.files[0];
and
let file = (<HTMLInputElement>e!.target)!.files[0];
Is there a way to make it work without having to use the strictNullChecks option in tsconfig?
Best regards