What am I not understanding about ColumnType?

(Apologize if this is very nooby I am new to kysely as of today) Used kysely-codegen and it spit out something like the following:
export type Int8 = ColumnType<
string,
bigint | number | string,
bigint | number | string
>;

export interface UserTable {
...
phoneOneCountryId: Generated<Int8>;
...
}
export type Int8 = ColumnType<
string,
bigint | number | string,
bigint | number | string
>;

export interface UserTable {
...
phoneOneCountryId: Generated<Int8>;
...
}
(Maybe it shouldn't be Generated? My current thought is code-gen marks that because the column has a default value? I'm struggling to find in kysely docs clear right/wrong here.) Which I then wrap:
export type NewUser = Insertable<UserTable>;
export type NewUser = Insertable<UserTable>;
However when I go to use like so:
const testNewUser: NewUser = {
...
phoneOneCountryId: 20,
...
};
const testNewUser: NewUser = {
...
phoneOneCountryId: 20,
...
};
I get compilation error:
Type 'number' is not assignable to type 'Int8'.ts(2322)
Type 'number' is not assignable to type 'Int8'.ts(2322)
---------------- If I understand how codegen set up Int8 correctly with ColumnType then it passed
bigint | number | string,
bigint | number | string,
as the InsertType (middle arg). So I wouldn't expect this to error - what am I missing here?
Solution:
So I figured out through combing through kysely-codegen closed issues that there is a differnece between the out-of-the-box kysely Generated type and the Generated type I was removing (that I thought was extra) that gets generated with codegen. When I restored for the codegen one the compilation issue went away. For reference current codegen type: ```export type Generated<T> = T extends ColumnType<infer S, infer I, infer U> ? ColumnType<S, I | undefined, U>...
Jump to solution
1 Reply
Solution
WhyDoThis
WhyDoThis5mo ago
So I figured out through combing through kysely-codegen closed issues that there is a differnece between the out-of-the-box kysely Generated type and the Generated type I was removing (that I thought was extra) that gets generated with codegen. When I restored for the codegen one the compilation issue went away. For reference current codegen type:
export type Generated<T> = T extends ColumnType<infer S, infer I, infer U>
? ColumnType<S, I | undefined, U>
: ColumnType<T, T | undefined, T>;
export type Generated<T> = T extends ColumnType<infer S, infer I, infer U>
? ColumnType<S, I | undefined, U>
: ColumnType<T, T | undefined, T>;
I dismissed the bot response before so I can't see how to mark this solved now.
Want results from more Discord servers?
Add your server