Type cannot be inferred when using returning on insert

I have this function and it is causing typescript errors
export async function inviteUsers(data: z.infer<typeof sendInvitesValidator>) {
const res = await db
.insert(schema.invites)
.values(
data.map((invite) => ({
email: invite.email,
roles: invite.roles,
accepted: false,
}))
)
.returning({ id: schema.invites.id })
.execute();

return res;
}
export async function inviteUsers(data: z.infer<typeof sendInvitesValidator>) {
const res = await db
.insert(schema.invites)
.values(
data.map((invite) => ({
email: invite.email,
roles: invite.roles,
accepted: false,
}))
)
.returning({ id: schema.invites.id })
.execute();

return res;
}
res is types correctly but I am getting this error
The inferred type of 'inviteUsers' cannot be named without a reference to '../../node_modules/drizzle-orm/query-builders/select.types'. This is likely not portable. A type annotation is necessary.
The inferred type of 'inviteUsers' cannot be named without a reference to '../../node_modules/drizzle-orm/query-builders/select.types'. This is likely not portable. A type annotation is necessary.
This is a simple project with no qorkspace, everything is installed in the same package
9 Replies
hachoter
hachoter12mo ago
I was originally using bun install but now tried with pnpm and got the same issue, the path in the error is for the local node_modules so it's not trying to reference something else
Angelelz
Angelelz12mo ago
Interesting, are you linking drizzle-orm from a local build? If not, can you provide a repro repo?
hachoter
hachoter12mo ago
I am not linking drizzle from anywhere, I am getting a repro now
hachoter
hachoter12mo ago
https://github.com/isaacfink/drizzle-bug-repro @Angelelz I created a repro, I am running this with bun but I tested with pnpm and got the same results
GitHub
GitHub - isaacfink/drizzle-bug-repro
Contribute to isaacfink/drizzle-bug-repro development by creating an account on GitHub.
hachoter
hachoter12mo ago
It might eb a tsconfig issue but I don't know what could cause it Found it, removing composite form tsconfig did the trick
Angelelz
Angelelz12mo ago
So, it is a non issue?
hachoter
hachoter12mo ago
I would still like to understand why its happening but yeah my issue is resolved
Angelelz
Angelelz12mo ago
TSConfig Reference - Docs on every TSConfig option
From allowJs to useDefineForClassFields the TSConfig reference includes information about all of the active compiler flags setting up a TypeScript project.
Angelelz
Angelelz12mo ago
Maybe due to the declaration? Since the types you needed some of them are internal, that's probably why it was complaining
Want results from more Discord servers?
Add your server