Michal SrbM
Convex Community6mo ago
1 reply
Michal Srb

v.optional generates incorrect TypeScript type in api

This code:
export const foo = query({
  args: {
    bla: v.optional(v.string()),
  },
  handler: async (ctx, args) => {}
});

Generates correct type for
foo
:

const foo: RegisteredQuery<"public", {
    bla?: ScopeName | undefined;
}, ....>


But the type is incorrect (imprecise) in the api:

foo: FunctionReference<"query", "public", {
    bla?: ScopeName;
}, ....>

Notice that
| undefined
is missing. This is a different type, and it matters when
compilerOptions.exactOptionalPropertyTypes
is set to
true
in tsconfig.

I'd guess it's a bug in
Expand
or in TS itself?
Was this page helpful?