Let's say I have a table called Examples
and the generated types look like this:
import type { ColumnType } from "kysely";
export type Generated<T> = T extends ColumnType<infer S, infer I, infer U>
? ColumnType<S, I | undefined, U>
: ColumnType<T, T | undefined, T>;
export interface Examples {
id: Generated<number>;
created_at: Generated<Date>;
updated_at: Generated<Date>;
text: string;
}
export interface DB {
examples: Examples;
}
If I'm using something like React or Svelte, and I want to type a prop e.g.:
import type { Examples } from "@db/schema";
type ExampleProps = {
example: Examples;
};
I'll get errors like the following for the Generated<number>
on the id
column (in this example, trying to set the value
attribute on an input
element):
Any way around this? Would it be best to create a file of different queries and infer the type of each result and export those:
const exampleQuery = await db.selectFrom('examples').selectAll().execute();
export type Example = (typeof exampleQuery)[number];
This seems a bit odd, however if I have different queries e.g. one where I selectAll
vs selecting certain fields, it seems great to have those typed separately and then I can just import the query from the file as well.
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too