Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Navigator interface no longer extends MSFileSaver #45612

Closed
jrmcpeek opened this issue Aug 28, 2021 · 6 comments
Closed

Navigator interface no longer extends MSFileSaver #45612

jrmcpeek opened this issue Aug 28, 2021 · 6 comments
Labels
Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript Working as Intended The behavior described is the intended behavior; this is not a bug

Comments

@jrmcpeek
Copy link

Bug Report

Recent changes to the Navigator interface for 4.4 removed previous extensions; however, the previously extended type is still present in lib.dom.d.ts and should be added back to the interface.

🔎 Search Terms

Navigator, MSFileSaver, msSaveBlob, msSaveOrOpenBlob

🕗 Version & Regression Information

Injected starting with 9d443b7

  • This prevents building

⏯ Playground Link

Playground link with relevant code

💻 Code

if (window.navigator.msSaveBlob) {
    console.log("Type works!")
}

if (window.navigator.msSaveOrOpenBlob) {
    console.log("Type works!")
}

🙁 Actual behavior

TS2339: Property 'msSaveOrOpenBlob' does not exist on type 'Navigator'.
TS2339: Property 'msSaveBlob' does not exist on type 'Navigator'.

🙂 Expected behavior

Appropriately typed file continues to build as it did previously.

@orta orta added Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript Working as Intended The behavior described is the intended behavior; this is not a bug labels Aug 28, 2021
@orta
Copy link
Contributor

orta commented Aug 28, 2021

Both of these have been marked from removal from the browsers and removed from the W3C specs, which means they were removed from the DOM.d.ts files as they follow the specs as summarized in microsoft/TypeScript-DOM-lib-generator#1029

@MartinJohns
Copy link
Contributor

You can use declaration merging and declare the types locally in your project.

@jrmcpeek
Copy link
Author

I figured it was probably something like that. We already worked around it with the declaration merging, so no issues there.

Now to focus on the real fix. Thanks!

@NickGrava
Copy link

You can use declaration merging and declare the types locally in your project.

Hi everyone! Сan someone give an example of how this can be done?

@MoSattler
Copy link

@NickGrava
Create a new file called navigator.d.ts and add this as content:

interface Navigator {
  msSaveOrOpenBlob: (blob: Blob) => void
}

this will add msSaveOrOpenBlob to navigator

nlewycky added a commit to nlewycky/toxcalc that referenced this issue Jan 7, 2022
nlewycky added a commit to nlewycky/toxcalc that referenced this issue Jan 7, 2022
@mesqueeb
Copy link

mesqueeb commented Feb 6, 2022

In case anyone comes looking here,
@MoSattler 's answer didn't work for me, and it only accept Blob while it should also accept base64 strings and a filename!

This fixed it for me:

declare global {
  interface Navigator {
    msSaveOrOpenBlob: (blobOrBase64: Blob | string, filename: string) => void
  }
}

I just added this at the top of the file where I was using this function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript Working as Intended The behavior described is the intended behavior; this is not a bug
Projects
None yet
Development

No branches or pull requests

6 participants