I have the following generated type from a GraphQL query.
type Maybe<T> = T | null
...
export type DealFragmentFragment = { __typename: "Deal" } & Pick<
Deal,
"id" | "registeringStateEnum" | "status" | "offerStatus"
> & {
users: Maybe<Array<{ __typename: "User" } & Pick<User, "id" | "name">>>
>
I have a React function that takes a User passed down from the above query.
function userCard({ user }) {
// ...do stuff
}
My question is how do I select the User subset from DealFragmentFragment?
function userCard({ user }: { user: DealFragmentFragment["users"] }) {
// ...do stuff
}
What goes after DealFragmentFragment["users"] to get "inside" of the array and Maybe to show the id and name properties?
Thank you!
console.log(DealFragmentFragment["users"])what do you see?console.logevaluates TS types. The compiler for the above code statesTypeScript error: Property 'user' does not exist on type 'Maybe<({ __typename: "User"; } & Pick<User, "id" | "name">)[]>'. TS2339