Reusable pgTable column helper - losing type : [x: string] instead of user_id

Hi, I am trying to create a reusable column to use accross multiple tables. If I use the following :
export const userId = char("user_id", {
  length: 10,
}).references(() => users.id);

I get the correct type in my KyselyDatabase interface.
user_id: ColumnType<string, string, string>;

I'd like it to be a function instead. But when I do the following :
export const userId = (name?: string) => {
  return char(name ?? "user_id", {
    length: 10,
  }).references(() => users.id);
};

I get the following type (thus breaking types accross all my db queries)
[x: string]: ColumnType<string | null, string, string>;
Was this page helpful?