admin管理员组

文章数量:1278823

The property msSaveOrOpenBlob doesn't exist on type Navigator after updating to the angular 13.

I know the Navigator.msSaveOrOpenBlob is being deprecated as per

I had an angular 12 application, now I am migrating to angular 13 and typescript have been updated to the latest version, but facing the issue of The property msSaveOrOpenBlob doesn't exist on type Navigator

what will be the alternate code for the below

if (window.navigator.msSaveOrOpenBlob) {
            navigator.msSaveOrOpenBlob(blob, filename);
        }

The property msSaveOrOpenBlob doesn't exist on type Navigator after updating to the angular 13.

I know the Navigator.msSaveOrOpenBlob is being deprecated as per https://developer.mozilla/en-US/docs/Web/API/Navigator/msSaveOrOpenBlob#browser_patibility

I had an angular 12 application, now I am migrating to angular 13 and typescript have been updated to the latest version, but facing the issue of The property msSaveOrOpenBlob doesn't exist on type Navigator

what will be the alternate code for the below

if (window.navigator.msSaveOrOpenBlob) {
            navigator.msSaveOrOpenBlob(blob, filename);
        }
Share Improve this question asked Nov 15, 2021 at 7:28 San JaisySan Jaisy 17.1k43 gold badges205 silver badges346 bronze badges 2
  • Angular 13 does not support Internet Explorer. Why don't you just drop the code? Even if you pile it, the condition will never be true – Christian Vincenzo Traina Commented Mar 28, 2022 at 10:07
  • @ChristianVincenzoTraina I was using this for Edge at one point. I think Edge changed to Chromium at some point; would that have made this useless also for Edge? – indigo Commented Aug 31, 2022 at 19:28
Add a ment  | 

3 Answers 3

Reset to default 6
let newVariable: any = window.navigator;
var newBlob = new Blob([res.body], { type: "application/csv" });
if (newVariable && newVariable.msSaveOrOpenBlob) {
    newVariable.msSaveOrOpenBlob(newBlob);
    return;
}

Found some of the references

https://github./microsoft/TypeScript-DOM-lib-generator/issues/1029 https://github./microsoft/TypeScript/issues/45612

Use the declaration merging and declare the types locally in your project work.

Declare below code in main.ts

  declare global{
    interface Navigator {
      msSaveOrOpenBlob?: (blob: any, defaultName?: string) => boolean
    }
  }

本文标签: javascriptmsSaveOrOpenBlob property doesn39t exist on type Navigator angular 13Stack Overflow