Randomly losing types for tables.

I have a mono repo setup for a bill tracking project, it's OSS so you can view it at https://github.com/sungmanito/mono -- part of the monorepo are shared drizzle definitions because I end up using them in more than one place (https://github.com/sungmanito/mono/tree/main/packages/db)

Currently I've lost types for my queries. This is not the first time this has happened, but previously the culprit was that I had upgraded the drizzle-orm version in one package without updating the other(s). Each of the packages and apps are using drizzle-orm 0.44.2, confirmed in my pnpm-lockfile that there are no other listed versions.

In the main web app I create a drizzle client:
import { drizzle } from 'drizzle-orm/node-postgres';
import { DB_URL } from '$env/static/private';
import Pg from 'pg';
import { exportedSchema } from '@sungmanito/db';

const client = new Pg.Pool({
  connectionString: DB_URL,
});

await client.connect();

export const db = drizzle(client, {
  logger: true,
  schema: exportedSchema,
});


and in the loader functions (sveltekit) I tend to do stuff like
import { db } from '$lib/server/db';
import { exportedSchema } from '@sungmanito/db';
export const load = async () => {
  const results = await db.select().from(exportedSchema.bills);
  return { results };
}


More confusing, is if i take any of the table definitions and just include them in the repo, it works fine.

The types that come back for a typical query, like where I'm loading all the bills, their most recent payment status, and the name of the household associated with that bill, is this

 ({
    [x: string]: unknown;
} | {
    [x: string]: unknown;
} | {
    [x: string]: unknown;
} | {
    [x: string]: unknown;
} | {
    [x: string]: unknown;
} | {
    [x: string]: unknown;
} | {
    [x: string]: unknown;
} | {
    [x: string]: unknown;
})[]


When it should be something more like
{ id: string; billName: string; householdName: string; householdId: string; ...}[]


Anyone got any ideas?

GitHub
Contribute to sungmanito/mono development by creating an account on GitHub.
GitHub
Contribute to sungmanito/mono development by creating an account on GitHub.
Was this page helpful?