Losing kysely types (using Kyselify) - getting [x: string]: any

Hello. I have some types problems using kysely with drizzle. I have the following config:
import { CamelCasePlugin, Kysely, PostgresDialect } from "kysely";
import { Kyselify } from "drizzle-orm/kysely";
import { createPool } from "#connectors/create-pool";
import {
posts,
} from "#schema";

export interface KyselyDatabase {
posts: Kyselify<typeof posts>;
}

export const db = new Kysely<KyselyDatabase>({
dialect: new PostgresDialect({
pool: createPool({
max: 1,
}),
}),
plugins: [new CamelCasePlugin()],
});
import { CamelCasePlugin, Kysely, PostgresDialect } from "kysely";
import { Kyselify } from "drizzle-orm/kysely";
import { createPool } from "#connectors/create-pool";
import {
posts,
} from "#schema";

export interface KyselyDatabase {
posts: Kyselify<typeof posts>;
}

export const db = new Kysely<KyselyDatabase>({
dialect: new PostgresDialect({
pool: createPool({
max: 1,
}),
}),
plugins: [new CamelCasePlugin()],
});
When I do the following query:
export const getPosts = async () => {
const posts = await db
.selectFrom("posts")
.select(["title", "id"])
.execute();
return posts ?? null;
};
export const getPosts = async () => {
const posts = await db
.selectFrom("posts")
.select(["title", "id"])
.execute();
return posts ?? null;
};
In vscode, I get the following type:
const getPosts: () => Promise<{
[x: string]: any;
}[]>
const getPosts: () => Promise<{
[x: string]: any;
}[]>
It doesn't infer the title and id types automatically so I have a bunch of type error in my code when using posts returned value. Am I doing something wrong or there is a problem with Kyselify?
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server