How to use useMutation with convex-ents. API object TYPE error
in my frontend i'm calling this api
const storeUser = useMutation(api.users.store);
but i get this type error. the function still runs and works as expected.
Property 'users' does not exist on type '{ clerkBackend: { AdminGetUserList: FunctionReference<"action", "public", {}, { id: string; email: string | undefined; firstName: string | null; }[] | null>; }; messageActions: { ...; }; }'
it cannot find the api because i have replaced...
// import { mutation, query } from './_generated/server';
with
import { mutation } from './functions';
this is part of my functions.ts
how can i fix this? As soon as put this back in
`
everything works.14 Replies
when i look at api.d.ts i can see the types are correct, and users is available. the only object tables available are "clerkbackend and messageActions" as they both use the generated, query and mutation sand not the custom ones.
Interesting, I don't see anything wrong with your code. You said it works at runtime, which I would assume means
npx convex dev
is pushing the code and not hitting type errors. So is the type error showing up in your editor or from something like npm run build
? My first step would be to restart typescript and eslint in your editor, or just restart the editor.I also don't see anything wrong, but it suggests that the custom
mutation
constructor you build with convex-helpers is not returning the correct type, so it doesn't show up in the API object.
Could you share a repo with a repro?shared a stripped version of the repo:
The store hook: https://github.com/AyoCodess/convex-ents-issue/blob/main/apps/mobile/src/hooks/useStoreUserEffect.ts
convex: https://github.com/AyoCodess/convex-ents-issue/tree/main/packages/api
api re-export: https://github.com/AyoCodess/convex-ents-issue/blob/main/packages/api/core.ts
GitHub
convex-ents-issue/apps/mobile/src/hooks/useStoreUserEffect.ts at ma...
Contribute to AyoCodess/convex-ents-issue development by creating an account on GitHub.
GitHub
convex-ents-issue/packages/api at main · AyoCodess/convex-ents-issue
Contribute to AyoCodess/convex-ents-issue development by creating an account on GitHub.
GitHub
convex-ents-issue/packages/api/core.ts at main · AyoCodess/convex-e...
Contribute to AyoCodess/convex-ents-issue development by creating an account on GitHub.
the issue is coming frin tge functions.ts
it cant use the custom mutation
user.ts
`
@Son I'm seeing a ton of errors when I run
npx tsc
(both from project directory and from the mobile
directory). I assume that this is caused by some of your tsconfig.json
config values.
Try to get a clean npx tsc
first.this is probably because i stripped down the project down apologies.
i think i worked it out...
My user table is using the standard convex mutation, as typed here in my functions.ts.
I've classed users to be typed as a legacy table. is that correct?
Where i think i went wrong was in the user.ts file i had swapped out the standard mutation function for the custom mutation n from fucntion.ts when it fact the code for the store mutation is not using the custom mutation at all right now.
``
so am i right in saying, the users.ts store function was using the custom mutation when it fact it should of used the standard mutation function as the "users" table it's marked as a legacy
And when i finally covert the store function to use the custom mutation function, then i will
no longer get the type error when i bring back in the code below?
instead of...
my theory was incorrect
i created a new file called relationship.ts with a function that used the custom mutation
``
it works at run time i get the result '500''
but no types
i updated the code and removed most of the typescript errors, whats left is related to comvex
`
this had no issues in my next js app
so its to do with expo, same imports
I'm still getting a bunch of errors (even when I revert to
import { mutation, query } from "./_generated/server";
) . Try to clone the repo, npm install, and then run npx tsc
.removed all non-related convex type errors. new repo
https://github.com/AyoCodess/hm-demo-2
GitHub
GitHub - AyoCodess/hm-demo-2
Contribute to AyoCodess/hm-demo-2 development by creating an account on GitHub.
found the issue. the baseConfig line 1
"extends": "@repo/typescript-config/base.json",
i commented out the base config which is below
`
types work as expected now. unbelievable.My guess would be that it is
"module": "NodeNext",
breaking things.