XMLHttpRequest does not exist in type window

I am working on a small asynchronous library for my projects. I decided to encode it in TypeScript, but my compiler gives me an error message 'XMLHttpRequest' does not exist on type 'Window', as the header says.

What I wanted to achieve was creating an ActiveXObject if there is no XMLHttprequest in the window.

if (window.XMLHttpRequest) {
    xmlhttp = new XMLHttpRequest();
 } else {
    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}

I do not need to turn it on, but I wonder why?


IDE I am using VS code (which also shows me an error) and I am compiling with gulp-tsify

+4
source share
1 answer

Try the following:

if ((<any>window).XMLHttpRequest) {
    xmlhttp = new XMLHttpRequest();
} else {
    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}

, Typescript , , ( , ), any, .

+9

Source: https://habr.com/ru/post/1665798/


All Articles