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

Breaking change in 1.18 -> Argument of type '"blob"' is not assignable to parameter of type 'ResponseType' #9639

Open
1 of 9 tasks
alXDraghiciu opened this issue Apr 15, 2024 · 0 comments
Labels
type:bug-suspected Suspected bug (not working as designed/expected). See “type:bug-confirmed” for confirmed bugs.

Comments

@alXDraghiciu
Copy link

alXDraghiciu commented Apr 15, 2024

Target SharePoint environment

SharePoint Online

What SharePoint development model, framework, SDK or API is this about?

💥 SharePoint Framework

Developer environment

Windows

What browser(s) / client(s) have you tested

  • 💥 Internet Explorer
  • 💥 Microsoft Edge
  • 💥 Google Chrome
  • 💥 FireFox
  • 💥 Safari
  • mobile (iOS/iPadOS)
  • mobile (Android)
  • not applicable
  • other (enter in the "Additional environment details" area below)

Additional environment details

  • SPFX 1.18.2
  • Node 18.17.1

Describe the bug / error

Cannot use MSGraphClientV3. The responseType function does not recognize strings (i.e. blob) as valid arguments, expecting a ResponseType type argument instead. This was not an issue in the previous version (1.17).

Example:

 private async _getUserProfilePicture(): Promise<HTMLImageElement | void> {
    return await this.context.msGraphClientFactory.getClient('3').then(
      async (graphclient: MSGraphClientV3) => {
        return await graphclient
          .api('/me/photo/$value')
          .responseType("blob")
          .get()
          // eslint-disable-next-line @typescript-eslint/no-explicit-any
          .then((blob: Blob): Promise<any> => {
            // eslint-disable-next-line no-async-promise-executor
            return new Promise(async (resolve, reject) => {
              const b64 = await blobToBase64(blob);
              const img = new Image();
              img.src = b64;
              this.properties.hasProfilePicture = true;
              return resolve(img);
            });
          })
          .catch((e) => {
            // ...
          });
      });

And the build produces this error:

Argument of type '"blob"' is not assignable to parameter of type 'ResponseType'.ts(2345)

Steps to reproduce

  1. Create a new folder and initialize a new SPFX solution:

    yo @microsoft/sharepoint
  2. Choose WebPart for the client-side component and React for template, leave everything else default
  3. Install the @microsoft/sp-http package for the MSGraphClientV3:

    npm i @microsoft/sp-http
  4. Modify config/serve.json with your SharePoint tenant URL
  5. Open up src/webparts/helloWorld/HelloWorldWebPart.ts
  6. Modify the onInit method to look like this:
  protected async onInit(): Promise<void> {
    await this.context.msGraphClientFactory.getClient('3').then(
      async (graphclient: MSGraphClientV3) => {
        return await graphclient
          .api('/me/photo/$value')
          .responseType("blob")
          .get()
          // eslint-disable-next-line @typescript-eslint/no-explicit-any
          .then((blob: Blob): Promise<any> => {
            // eslint-disable-next-line no-async-promise-executor
            return new Promise(async (resolve, reject) => {
              return resolve(blob);
            });
          })
      });
  }
  1. Run the gulp serve command
  2. The build will fail:

    Error - [tsc] src/webparts/helloWorld/HelloWorldWebPart.ts(45,25): error TS2345: Argument of type '"blob"' is not assignable to parameter of type 'ResponseType'.

Expected behavior

The build to succeed.

@alXDraghiciu alXDraghiciu added the type:bug-suspected Suspected bug (not working as designed/expected). See “type:bug-confirmed” for confirmed bugs. label Apr 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:bug-suspected Suspected bug (not working as designed/expected). See “type:bug-confirmed” for confirmed bugs.
Projects
None yet
Development

No branches or pull requests

1 participant