Is there a way to type a nextjs endpoint, so when sending a request I directly know the returned type?
Example Endpoint
const getHandler = async (
req: NextApiRequest,
res: NextApiResponse,
prisma: PrismaClient
) => {
// query data and type it somehow?
}
Example Query
const {data: myData} = useQuery(["myKey"], () => axios.get("/api/myEndpoint"))
No matter what I try, the type of myData is always AxiosResponse<any, any> | undefined
I know that I just can create an interface and type type response again, but is there any other way? I appreciate every advice, thanks in advance!