2

So I'm generating types from a GraphQL schema using graphql-codegen and I get things like:

export type CustomersQuery = (
  { __typename?: 'Query' }
  & { customers?: Maybe<(
    { __typename?: 'CustomerPaginator' }
    & { data: Array<(
      { __typename?: 'Customer' }
      & Pick<Customer, 'id' | 'uuid' | 'name' | 'status' | 'createdAt' | 'accountNumber'>
    )> }
  )> }
);

I have a React component that gets supplied the contents of one customers.data array element as a prop. I figure I should be specifying that requirement in it's interface right? Currently I have:

interface MyComponentProps {
  customer?: Partial<Customer>
}

How can I be more specific and reference that Pick from type CustomersQuery in my interface?

Thanks!

3
  • Does this answer your question? Typescript: Retrieve element type information from array type Commented Dec 11, 2020 at 8:38
  • 2
    Also is this what you want: Partial<Omit<NonNullable<CustomersQuery['customers']>['data'][number], '__typename'>> Commented Dec 11, 2020 at 8:40
  • Ah that is! Thanks very much ideed! Commented Jan 4, 2021 at 15:17

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.