msgraph-typescript-typings icon indicating copy to clipboard operation
msgraph-typescript-typings copied to clipboard

Not fully understanding the purpose of this project

Open badsyntax opened this issue 3 years ago • 3 comments

Hi there. I've been using the microsoft graph client and the types in this repo.

The thing I don't fully understand, is why the types are separate from the microsoft graph client project, and why I need to explicitly typecast. It relies on me, the consumer, knowing the types ahead of time. I don't know the request or response data schema for all the endpoints, so how am I supposed to typecast? This approach seems a little risky to me, I could be typecasting wrong and could be using the wrong data structures.

Can someone clarify the situation and explain the microsoft graph client doesn't just use the types in this repo? It would make consumers's lives a lot better!

The client should provide the types for every endpoint. In the example below, as i consumer, I expect the client to tell me the types it expects:

// `user` should be typed by default
// the return type should be typed by default
client.api(`/users/${id}`).patch(user);

If the types cannot be combined with the client, can i suggest a slightly better approach (imo) for handling types. Instead of typecasting we can use generics:

client.api(`/users/${id}`).patch<RequestType, ResponseType>(user);

AB#8842

badsyntax avatar Apr 03 '21 07:04 badsyntax

@badsyntax Thank you for your suggestion! The Microsoft Graph Client is the core library which is intended to be light weight with a set of specific functionalities. The typings library is intended to be an interface to the regularly updated metadata.

However, we do have plans to improve on the points you put forward in this issue.

nikithauc avatar Apr 07 '21 07:04 nikithauc

Thanks for the reply @nikithauc Tbh I still don't fully understand why it's up to the consumer to provide the correct types. Perhaps another package is required? One that provides the correct types for msgraph-sdk-javascript, eg msgraph-sdk-typescript.

badsyntax avatar Apr 07 '21 09:04 badsyntax