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

Argument of type 'WebPartContext' is not assignable to parameter of type 'ISPFXContext'. #2329

Closed
1 task
Ofer-Gal opened this issue Jun 26, 2022 · 4 comments
Closed
1 task

Comments

@Ofer-Gal
Copy link

Category

  • Enhancement
  • [] Bug
  • [] Question
  • [ X] Documentation gap/issue

Version

Please specify what version of the library you are using: [ 3.4.1 ]

Please specify what version(s) of SharePoint you are targeting: [ SPO SPFx 1.15.0 ]

If you are not using the latest release, please update and see if the issue is resolved before submitting an issue.

Expected / Desired Behavior / Question

No issue with code from the example

Observed Behavior

Now that I upgraded to SPFx 1.15.0 (with newer TS and strict ESlint) I get TS Error:

Argument of type 'WebPartContext' is not assignable to parameter of type 'ISPFXContext'.
The types of 'msGraphClientFactory.getClient' are incompatible between these types.
Type '(version: "3") => Promise' is not assignable to type '() => Promise'.ts(2345)

Steps to Reproduce

Just use the code from the documentation the error will show.

Is PnP.JS not ready for 1.15.1? any workaround that will work?

Thank you for your help!

@IvanTheBearable
Copy link

MSGraphClientFactory in 1.15 is defined with this getClient method:
getClient(version: '3'): Promise<MSGraphClientV3>;

ISPFXContext declares it as:

msGraphClientFactory?: {
    getClient: () => Promise<any>;
};

If you are not using Graph then this workaround should get past the compiler errors:
spfi().using(SPFx((this.context as unknown) as ISPFXContext))

If you are using Graph then it may be more complex. I don't know the inner workings of PnPjs well enough to be sure. A quick code search seems to suggest it doesn't get used at all but I am probably missing something.

@Ofer-Gal
Copy link
Author

the code is not in the web part "init" so "this.context" does not exist but comes as parameter Type "WebPartContext"

@juliemturner
Copy link
Collaborator

@IvanTheBearable is correct, this is a viable typing workaround:

spfi().using(SPFx((context as unknown) as ISPFXContext))

I prefer this:

spfi().using(SPFx({pageContext: context.pageContext}));

And no we do not use the msGraphClient in PnPjs.

We'll work on updates to address SPFx 1.15's release for our next version.

@github-actions
Copy link

This issue is locked for inactivity or age. If you have a related issue please open a new issue and reference this one. Closed issues are not tracked.

@github-actions github-actions bot locked and limited conversation to collaborators Jul 11, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants