Skip to content

Typescript error joining on an optional field with eq. #299

@thruflo

Description

@thruflo

I have event and user collections defined with the following (abbreviated) zod schemas:

const userSchema = z.object({
  id: z.uuid()
})

const eventSchema = z.object({
  user_id: z.uuid().optional()
})

If I try to do an inner join between them like this:

query
  .from({ event: eventCollection })
  .innerJoin(
    { user: userCollection },
    ({ event, user }) => eq(event.user_id, user.id)
  )

I get a typescript error:

No overload matches this call.
  Overload 1 of 3, '(left: RefProxy<string | undefined>, right: string | RefProxy<string | undefined> | BasicExpression<string | undefined> | undefined): BasicExpression<...>', gave the following error.
    Argument of type 'RefProxy<string | undefined> | undefined' is not assignable to parameter of type 'RefProxy<string | undefined>'.
      Type 'undefined' is not assignable to type 'RefProxy<string | undefined>'.
  Overload 2 of 3, '(left: string | number | boolean | BasicExpression<string | number | boolean>, right: string | number | boolean | BasicExpression<string | number | boolean>): BasicExpression<...>', gave the following error.
    Argument of type 'RefProxy<string | undefined> | undefined' is not assignable to parameter of type 'string | number | boolean | BasicExpression<string | number | boolean>'.
      Type 'undefined' is not assignable to type 'string | number | boolean | BasicExpression<string | number | boolean>'.
  Overload 3 of 3, '(left: Aggregate<unknown>, right: any): BasicExpression<boolean>', gave the following error.
    Argument of type 'RefProxy<string | undefined> | undefined' is not assignable to parameter of type 'Aggregate<unknown>'.
      Type 'undefined' is not assignable to type 'Aggregate<unknown>'.

         .innerJoin({ user: userCollection }, ({ event, user }) => eq(event.user_id, user.id))

If I swap the order of the arguments to eq then I don't get the error. Is this correct / expected? Or should eq handle optional fields as the first argument in this situation?

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions