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
3 Replies
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:
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?@sodic one for you
Hey @caqlarreizz, sorry for the delay. Still need help with this?