Using Prisma types elsewhere

This might be a really silly question, Im sure the answer is super simple, I can't find the answer in docs though (thinking about it this is probably a more Typescript question)..

I have this TRPC call which returns some data with multiple relations: const parts = trpc.partDetails.getAll.useQuery();

The type for parts.data is

PartDetail & {
    partTypes: PartTypes[];
    parts: Part[];
    cars: Car[];
})[]`

This works great when working with parts.data, but I want to use that type elsewhere. Right now (embarrassingly) I just paste out the entire type where I want to use it. Example:

 const [selectedPart, setSelectedPart] = useState<
    | (PartDetail & {
        partTypes: PartTypes[];
        parts: Part[];
        cars: Car[];
      })
    | null
  >(null);


I KNOW this can't be the right way to do it, but how can I just make the state use the type from parts.data?

The closest I've got is const [selectedPart, setSelectedPart] = useState<typeof parts.data | null>(null); but I can't get it right!
Was this page helpful?