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

No type for API responses that return a list of values

Open M1kep opened this issue 4 years ago • 5 comments

I've found that when querying endpoints such as https://graph.microsoft.com/v1.0/groups I cannot find any types that match up with the response structure shown below:

interface valuesResponseExample<T> {
    @odata.context: string,
    @odata.nextLink?: string,
    value: T[]
}

Is this the intended behavior, and if so what is the suggested method for working around this? AB#8341

M1kep avatar Mar 01 '21 03:03 M1kep

@M1kep This is intended behavior.

Example of using the Group type in this case -

const res = await client.api("/groups").get();
const group = res.value[0] as Group;

Please let me know if you have any more questions.

nikithauc avatar Mar 04 '21 22:03 nikithauc

+1. Having types that encompass the @odata fields (both in the envelope and inside the entity) would be cool, especially for delta sync endpoints to easily get at @odata.nextLink and @odata.deltaLink.

markfields avatar Mar 25 '21 00:03 markfields

I defined my own type for this purpose:

type ODataResponse<T> = {
    [key: string]: any;
    value: T[];
}

Maybe it could be expanded upon to actually list some the valid @odata properties for ease of use if you need them in code? (e.g. @odata.nextLink)

markfields avatar Mar 25 '21 17:03 markfields

Bit out of topic but how can I remove the @data props from each response?

ss

richban avatar Jun 23 '21 09:06 richban

@M1kep This is intended behavior.

I think this really shouldn't be the intended behavior

Jonas-Seiler-Wave avatar Mar 01 '22 13:03 Jonas-Seiler-Wave