Self referencing nullable ID field not assigneable in a `eq` statement

I am not sure if I encountered another edge case but basically I have a self-referencing table where the reference can be nullable
export const carrierTasks = pgTable('carrier_tasks', {
id: uuid('id').primaryKey().defaultRandom(),
nextTaskId: uuid('next_task_id').references((): AnyPgColumn => carrierTasks.id),
isCurrent: boolean('is_current').default(false).notNull(),
});
export const carrierTasks = pgTable('carrier_tasks', {
id: uuid('id').primaryKey().defaultRandom(),
nextTaskId: uuid('next_task_id').references((): AnyPgColumn => carrierTasks.id),
isCurrent: boolean('is_current').default(false).notNull(),
});
await db.transaction(async (tx) => {
const currentTasks = await tx
.delete(carrierTasks)
.where(eq(carrierTasks.isCurrent, true))
.returning({ nextTaskId: carrierTasks.nextTaskId })

const currentTask = currentTasks?.[0];
if (!currentTask) {
throw new Error("Carrier task not found or not in current state");
}

await tx
.update(carrierTasks)
.set({ isCurrent: true })
.where(eq(carrierTasks.id, currentTask.nextTaskId))
await db.transaction(async (tx) => {
const currentTasks = await tx
.delete(carrierTasks)
.where(eq(carrierTasks.isCurrent, true))
.returning({ nextTaskId: carrierTasks.nextTaskId })

const currentTask = currentTasks?.[0];
if (!currentTask) {
throw new Error("Carrier task not found or not in current state");
}

await tx
.update(carrierTasks)
.set({ isCurrent: true })
.where(eq(carrierTasks.id, currentTask.nextTaskId))
1 Reply
volks
volks14mo ago
Which is resulting in
typescript: No overload matches this call.
Overload 1 of 2, '(left: Aliased<string | null>, right: string | Placeholder<string, any> | SQLWrapper | AnyColumn | null): SQL<unknown>', gave the following error.
Argument of type 'PgUUID<{ tableName: "carrier_tasks"; data: string; name: "id"; driverParam: string; notNull: true; hasDefault: true; }>' is not assignable to parameter of type 'Aliased<string | null>'.
Type 'PgUUID<{ tableName: "carrier_tasks"; data: string; name: "id"; driverParam: string; notNull: true; hasDefault: true; }>' is missing the following properties from type 'Aliased<string | null>': sql, fieldAlias, getSQL
Overload 2 of 2, '(left: PgUUID<{ tableName: "carrier_tasks"; data: string; name: "id"; driverParam: string; notNull: true; hasDefault: true; }>, right: string | Placeholder<string, any> | SQLWrapper | AnyColumn): SQL<...>', gave the following error.
Argument of type 'string | null' is not assignable to parameter of type 'string | Placeholder<string, any> | SQLWrapper | AnyColumn'.
Type 'null' is not assignable to type 'string | Placeholder<string, any> | SQLWrapper | AnyColumn'.
typescript: No overload matches this call.
Overload 1 of 2, '(left: Aliased<string | null>, right: string | Placeholder<string, any> | SQLWrapper | AnyColumn | null): SQL<unknown>', gave the following error.
Argument of type 'PgUUID<{ tableName: "carrier_tasks"; data: string; name: "id"; driverParam: string; notNull: true; hasDefault: true; }>' is not assignable to parameter of type 'Aliased<string | null>'.
Type 'PgUUID<{ tableName: "carrier_tasks"; data: string; name: "id"; driverParam: string; notNull: true; hasDefault: true; }>' is missing the following properties from type 'Aliased<string | null>': sql, fieldAlias, getSQL
Overload 2 of 2, '(left: PgUUID<{ tableName: "carrier_tasks"; data: string; name: "id"; driverParam: string; notNull: true; hasDefault: true; }>, right: string | Placeholder<string, any> | SQLWrapper | AnyColumn): SQL<...>', gave the following error.
Argument of type 'string | null' is not assignable to parameter of type 'string | Placeholder<string, any> | SQLWrapper | AnyColumn'.
Type 'null' is not assignable to type 'string | Placeholder<string, any> | SQLWrapper | AnyColumn'.
Since currentTask.nextTaskId is of type string | null . There are easy workarounds but this doesn't seem like the appropriate behavior