typescript - İnternet Explorer 11'de Fetch polyfill farklı bir Response nesnesine sahip


Şu anda Internet Explorer 11 ve Fetch API ile uğraşıyorum.

Aşağıdaki fetch çağrısını TypeScript kullanarak yapıyorum:

await fetch(theForm.action, { method: theForm.method, body: formData, credentials: "include" })
    .then((response: Response) => {
        if (response.status === 500)
            throw Error(response.statusText);

        if (response.redirected && response.url)
            return window.location.href = response.url;

        return response.json();
    })
    .catch((error: Error) => {
        return this.setState({ isSubmitting: false, internalServerError: error });
    });

Kod ts ile derlenip ES2015'e, sonra da babel kullanılarak ES5'e indiriliyor. Ayrıca babel-polyfill ekledim. Örnek kod, IE dışındaki diğer tarayıcılarda beklendiği gibi çalışıyor. Görünüşe göre, IE'deki Response nesnesi tamamen farklı ve redirected özelliğine sahip bile değil ve url her zaman boş.

Bunu IE'de çalıştırmak için kullanmam gereken bir polyfill var mı? Ve yoksa, iyi bir geçici çözüm ne olurdu?

Cevap #1

MDN'nin Response için tarayıcı uyumluluk tablosu, redirected özelliğinin IE'de mevcut olmadığını söylüyor.

https://github.com/github/fetch gibi bir polyfill kullanmayı ve https://github.com/github/fetch#obtaining-the-response-url adresindeki API önerisi ile birlikte denemeyi düşünebilirsiniz.