Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignorable TypeScript error when using RawBuilder inside jsonAgg's orderBy #1300

Open
JamesDonnelly opened this issue Dec 23, 2024 · 0 comments

Comments

@JamesDonnelly
Copy link

JamesDonnelly commented Dec 23, 2024

Assume I have a pet table which contains entries like:

id activities
123 { "breakfast": 8, "walk": 15, "dinner": 18, ...}

I'm able to use the RawBuilder when ordering at a query level, and TypeScript has no issue with this:

const rows = await db
  .selectFrom("pet")
  .orderBy(sql`pet.activities->>'breakfast'`)
  .execute();

https://kyse.link/4SqYL

However if I do the same when calling fn.jsonAgg, TypeScript errors:

await db
  .selectFrom("pet")
  .select(({ fn }) => [
    fn.jsonAgg('pet')
      .orderBy(sql`pet.activities->>'breakfast'`)
      .as('activities')
  ])
  .execute();

https://kyse.link/61vQv

Argument of type 'RawBuilder' is not assignable to parameter of type 'DynamicReferenceBuilder | StringReference<Database, "pet">'.
Type 'RawBuilder' is missing the following properties from type 'DynamicReferenceBuilder': #private, dynamicReference, refType

Fortunately this can be ignored by sticking a // @ts-ignore comment above the erroring line - the query executes as expected - but this shouldn't be necessary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant