3

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.org/en-US/docs/Web/API/Navigator/msSaveOrOpenBlob#browser_compatibility

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);
        }
2
  • Angular 13 does not support Internet Explorer. Why don't you just drop the code? Even if you compile it, the condition will never be true 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? Commented Aug 31, 2022 at 19:28

3 Answers 3

6
let newVariable: any = window.navigator;
var newBlob = new Blob([res.body], { type: "application/csv" });
if (newVariable && newVariable.msSaveOrOpenBlob) {
    newVariable.msSaveOrOpenBlob(newBlob);
    return;
}
Sign up to request clarification or add additional context in comments.

1 Comment

I didn't test it, but I suppose that TypeScript infers the type, so nothing changes. Maybe would be correct doing window.navigator as unknown as any, but as I said in my comment the whole snippet is just useless
2

Found some of the references

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

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

Comments

0

Declare below code in main.ts

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.