I have a generated type that looks like this:
export type GetUserWithMembershipsQuery = {
getUser: {
__typename: 'User';
id: string;
memberships: {
__typename: 'ModelUserMembershipConnection';
items: Array<{
__typename: 'UserMembership';
id: string;
createdOnDate: string | null;
renewedOnDate: string | null;
expiresOnDate: string | null;
membershipPhotoFileName: string | null;
} | null> | null;
} | null;
} | null;
};
I know I can get the type of the getUser by saying GetUserWithMembershipQuery['getUser'].
I'm wondering how I can extract the type of the items array within the memberships object from within that type, or if it's possible?
I would like to end up with something like:
type ItemType = GetUserWithMembershipQuery['getUser']['memberships']['items'][0]
Where the resulting type is:
{
__typename: 'UserMembership';
id: string;
createdOnDate: string | null;
renewedOnDate: string | null;
expiresOnDate: string | null;
membershipPhotoFileName: string | null;
} | null
I have tried going down one more level by using GetUserWithMembershipQuery['getUser']['memberships'], but I get an error saying that the 'Property memberships does not exist on type ...'
Is this because getUser or memberships is possibly null? Is there a way I can extract this type? Any help pointing to resources with how I can better understand this would be a great help.
Thank you.