Skip to content

Suggestion: Generic OData response type #299

Description

@Jonas-Seiler-Wave

I think this library should include a type to match the OData response signature, as these properties are very important to consider in certain scenarios and I don't think the library consumer should have to define this type themselves or have to rely on another library.

Concretely, I suggest an implementation that ideally enables the following Angular code to compile

(this.http as HttpClient)
      .get<ExampleODataType<User>>('https://graph.microsoft.com/v1.0/me')
      .subscribe((response) => {
        console.log(response['@odata.context']);
        console.log(response.displayName);
      });
      
(this.http as HttpClient)
      .get<ExampleODataType<User[]>>('https://graph.microsoft.com/v1.0/users?$count')
      .subscribe((response) => {
        console.log(response['@odata.count']);
        console.log(response['@odata.nextLink']);
        console.log(response.value[0].displayName);
      });  
      

A simpler alternative to this could be a Type containing just the OData properties which one can make intersections with

(this.http as HttpClient)
      .get<User & ExampleODataType>('https://graph.microsoft.com/v1.0/me')
      .subscribe((response) => {
        console.log(response['@odata.context']);
        console.log(response.displayName);
      });
      
(this.http as HttpClient)
      .get<{ value: User[] } & ExampleODataType>('https://graph.microsoft.com/v1.0/users?$count')
      .subscribe((response) => {
        console.log(response['@odata.count']);
        console.log(response['@odata.nextLink']);
        console.log(response.value[0].displayName);
      });  
      

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions