"Generated" is created in output, but Kysely has this type
matthiasfeist opened this issue · comments
I noticed that when I run the codegen, I get the following lines in my output file:
export type Generated<T> = T extends ColumnType<infer S, infer I, infer U>
? ColumnType<S, I | undefined, U>
: ColumnType<T, T | undefined, T>;
However, Kysely already exports a "Generated" type via import type { Generated } from 'kysely';
, so I was wondering why codegen is creating its own type?
I noticed the same thing and was wondering why. The Kysely version of Generated looks like it doesn't account for T
possibly already being an instance of ColumnType the way this one does, but I haven't quite figured out why yet. Looks like ColumnType
in Kysely defaults the S
, I
, and U
parameters there to SelectType
anyways, so it maybe it works out the same?
Definitely doesn't seem to be a problem, just interested in understanding the codebase a little better.
Oh right! I knew I added my own Generated
implementation for a reason.
Some types already use ColumnType
:
export type Json = ColumnType<JsonValue, string, string>;
export type Timestamp = ColumnType<Date, Date | string, Date | string>;
So this special type is necessary in order to do this:
export interface User {
created_at: Generated<Timestamp>;
// ^ ColumnType<Date, Date | string | undefined, Date | string>
}
Otherwise the type would be equal to this monstrosity:
export interface User {
created_at: Generated<Timestamp>;
// ^ ColumnType<
// ColumnType<Date, Date | string, Date | string>,
// ColumnType<Date, Date | string, Date | string> | undefined,
// ColumnType<Date, Date | string, Date | string>
// >
}
I just ran into this issue as I had removed it thinking it was in conflict/redundant to kysely's Generated type. Any appetite for renaming the Generated type codegen spits out to maybe something that describes the intent / difference?