You can tell TypeScript which type this should have by adding it as a function parameter:
function onload(this: HTMLImageElement) {
const {width, height} = this
}
The parameter will be ignored when compiling to JavaScript.
See https://www.typescriptlang.org/docs/handbook/2/functions.html#declaring-this-in-a-function
According to the code you provided I do not see a way to use this pointer as newImg.
But you will be able to use const{width,height} = newImg.somethingYouWannaDo().
function onload(img){
const {width, height} = img
}
Isn't onload passed the img?