Shahen 🔺
Shahen 🔺•4mo ago

ts-api-spec no type safety

Hello guys, I am trying multiple repos. I have a simple "tasks"(same as example in docs) schema and function in project 1. I ran npx convex-helpers ts-api-spec, copied the code over to project 2 in api.ts But I am not getting any type safety when calling useQuery. api.ts example:
import { FunctionReference, anyApi } from "convex/server";
import { GenericId as Id } from "convex/values";

export const api: PublicApiType = anyApi as unknown as PublicApiType;
export const internal: InternalApiType = anyApi as unknown as InternalApiType;

export type PublicApiType = {
auth: {
signIn: FunctionReference<
"action",
"public",
{
params?: any;
provider?: string;
refreshToken?: string;
verifier?: string;
},
any
>;
signOut: FunctionReference<"action", "public", Record<string, never>, any>;
};
tasks: {
get: FunctionReference<"query", "public", Record<string, never>, any>;
};
};
export type InternalApiType = {};
import { FunctionReference, anyApi } from "convex/server";
import { GenericId as Id } from "convex/values";

export const api: PublicApiType = anyApi as unknown as PublicApiType;
export const internal: InternalApiType = anyApi as unknown as InternalApiType;

export type PublicApiType = {
auth: {
signIn: FunctionReference<
"action",
"public",
{
params?: any;
provider?: string;
refreshToken?: string;
verifier?: string;
},
any
>;
signOut: FunctionReference<"action", "public", Record<string, never>, any>;
};
tasks: {
get: FunctionReference<"query", "public", Record<string, never>, any>;
};
};
export type InternalApiType = {};
3 Replies
Jordan22
Jordan22•4mo ago
hi! do you have args and returns validators defined on your convex functions? we can’t generate types for you if you don’t have them defined
Shahen 🔺
Shahen 🔺OP•4mo ago
ahh i see, can you point me out to how the return validators work?
jamwt
jamwt•4mo ago
see the "returns" field when you create a query/mutation/action: https://docs.convex.dev/functions/validation#adding-validators
Argument and Return Value Validation | Convex Developer Hub
Argument and return value validators ensure that

Did you find this page helpful?