tRPCttRPC
Powered by
boneyB
tRPC•3y ago•
7 replies
boney

How to infer type of a nested object from app router output?

I have a tRPC router than returns a nested object through a db query. It looks like this:

ILessonCommentProps.comments: ({
    _count: {
        likes: number;
        comments: number;
        bookmarks: number;
    };
    comments: ({
        user: GetResult<{
            id: string;
            displayName: string | null;
            email: string | null;
            emailVerified: Date | null;
            ... 17 more ...;
            updatedAt: Date;
        }, unknown>;
        subComments: GetResult<...>[];
    } & GetResult<...>)[];
    bookmarks: {
        ...;
    }[];
    likes: {
        ...;
    }[];
} & GetResult<...>) | null
ILessonCommentProps.comments: ({
    _count: {
        likes: number;
        comments: number;
        bookmarks: number;
    };
    comments: ({
        user: GetResult<{
            id: string;
            displayName: string | null;
            email: string | null;
            emailVerified: Date | null;
            ... 17 more ...;
            updatedAt: Date;
        }, unknown>;
        subComments: GetResult<...>[];
    } & GetResult<...>)[];
    bookmarks: {
        ...;
    }[];
    likes: {
        ...;
    }[];
} & GetResult<...>) | null


I'd like to infer the type of the
comments
comments
property to use as an interface for props on a component. I tried doing this but this doesn't work:

interface ILessonCommentProps {
  comments: AppRouterOutputs['lessonBuilder']['getLessonLikesCommentsBookmarks']['comments'];
}
interface ILessonCommentProps {
  comments: AppRouterOutputs['lessonBuilder']['getLessonLikesCommentsBookmarks']['comments'];
}


I was wondering if this is even possible?
tRPCJoin
Move Fast & Break Nothing. End-to-end typesafe APIs made easy.
5,015Members
Resources
Recent Announcements

Similar Threads

Was this page helpful?

Similar Threads

Infer query type of `data`
bill92Bbill92 / ❓-help
2y ago
How to infer types of a query
HussamHHussam / ❓-help
3y ago
Output properties missing on frontend results (Type Infer)
FakeTechExecFFakeTechExec / ❓-help
3y ago