Generic type can not be seen while using wasp/client/operations

I have created a function that in db/operation.ts and i am using it in routes/informationPage.tsx like "import {getTableData} from 'wasp/client/operations'; Thats meaning i am calling this function through the wasp. In operations.ts file the function is written like " interface getTableDataProps<T> { ........ }; export const getTableData = async <T>(props: getTableDataProps<T>): Promise<T[]> => { ...... } However, i am getting this error and when we import function from wasp/client/operations it seems like no T generic type and if we imports it directly from operations.ts file it has generic type <T> so that i can call the function. Otherwise I cannot call the function through the wasp
No description
No description
No description
3 Replies
kapa.ai
kapa.ai3mo ago
Hi @caqlarreizz. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Based on the information provided in the knowledge sources, it seems that there might be a misunderstanding about how Wasp handles operations. In Wasp, operations are defined in a specific way and they are typed using the types that Wasp generates for you. For example, in the Wasp documentation (https://wasp-lang.dev/docs#so-what-does-the-code-look-like), a query is defined as follows:
import { type GetRecipes } from "wasp/server/operations";
import { type Recipe } from "wasp/entities";

export const getRecipes: GetRecipes<{}, Recipe[]> = async (_args, context) => {
return context.entities.Recipe.findMany( // Prisma query
{ where: { user: { id: context.user.id } } }
);
};
import { type GetRecipes } from "wasp/server/operations";
import { type Recipe } from "wasp/entities";

export const getRecipes: GetRecipes<{}, Recipe[]> = async (_args, context) => {
return context.entities.Recipe.findMany( // Prisma query
{ where: { user: { id: context.user.id } } }
);
};
In this example, GetRecipes is a type that Wasp generates based on the query definition in the .wasp file. The type arguments of GetRecipes are used to specify the input and output types of the query. However, in your case, you are trying to define a generic function with a custom interface. This might not be compatible with how Wasp handles operations. If you want to use a generic type in your operation, you might need to define it in a different way that is compatible with Wasp. Unfortunately, the knowledge sources do not provide enough information on how to do this. I would recommend checking the Wasp documentation (https://wasp-lang.dev/docs) and the Wasp GitHub issues (https://github.com/wasp-lang/wasp/issues) for more information on how to define operations with generic types. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @caqlarreizz, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist: Perhaps try again in 15mins?
miho
miho3mo ago
@sodic one for you
Filip
Filip3mo ago
Hey @caqlarreizz, sorry for the delay. Still need help with this?
Want results from more Discord servers?
Add your server