pnp / pnpjs

Fluent JavaScript API for SharePoint and Microsoft Graph REST APIs
https://pnp.github.io/pnpjs/
Other
749 stars 305 forks source link

Type mismatch for graph user #2921

Closed anapeksha closed 7 months ago

anapeksha commented 7 months ago

What version of PnPjs library you are using

3.x

Minor Version Number

22

Target environment

SharePoint Framework

Additional environment details

I am using Node 18.19.0 with typescript 4 and @pnp 3

Question/Request

I am creating a custom PeoplePicker to be used in my other projects. But the problem I noticed was:

graph.users.getById(emailId)().then((response)=>console.log(response));

Now the response is typed as User which is not exported from the library.

P.S. - User is a class with type as IGraphInvokableFactory

Suggest how to perfectly type state values without making the variables as type any or unknown

patrick-rodgers commented 7 months ago

Thanks, this is just a case where we have assigned the wrong type to the return. The data is correct and is of type:

import { User } from "@microsoft/microsoft-graph-types";

anapeksha commented 7 months ago

Kindly help fix it for future releases. Also do update the jsdocs for graph.users.search()

juliemturner commented 7 months ago

@anapeksha - it would be our intent to do so but also, we accept pull requests since this is a community effort.

anapeksha commented 7 months ago

Sure! Thank you so much for your help and support.

I also had a question: How to get user photo in the same call as the user search?

As in:

graph.users
        .search(email)()
        .then((response) => {
          setUserResults(response);
        })
        .catch((error) => {
          setError(error);
        });
{userResults.map((value, index)=>(
       <ul>
          <img src={value.photo} alt={value.displayName}/>
          <li>{value.displayName}</li>
       </ul>
)

Currently, the photo is of type ProfilePhoto and has {id, width, height}. How to make it usable in the img:src.

juliemturner commented 7 months ago

In the future, please post a new issue if you're changing topic. That said the docs reference the way to get the actual photo: https://pnp.github.io/pnpjs/graph/photos/#current-user-photo

anapeksha commented 7 months ago

Thank you for the support.

juliemturner commented 7 months ago

Reopening to track bug.

juliemturner commented 7 months ago

Closed as after verifying this is typed properly and returning the graph User type. We don't explicitly export the graph types, they should be imported as referenced by @patrick-rodgers above: https://github.com/pnp/pnpjs/issues/2921#issuecomment-1914924175

github-actions[bot] commented 7 months ago

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.