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

[BUG]: Typescript error on having 0.29.0 #1515

Closed
autosync-1 opened this issue Nov 15, 2023 · 7 comments
Closed

[BUG]: Typescript error on having 0.29.0 #1515

autosync-1 opened this issue Nov 15, 2023 · 7 comments
Labels
bug Something isn't working

Comments

@autosync-1
Copy link

What version of drizzle-orm are you using?

0.29.0

What version of drizzle-kit are you using?

0.19.13

Describe the Bug

In select with having gets an Typescript error i worked well in 0.28.6 vesion
typescript: Property 'having' is missing in type 'Omit<import("C:/Users/hitech/code/autosync_nest/node_modules/.pnpm/drizzle-orm@0.29.0_@types+pg@8.10.7_pg@8.11.3/node_modules/drizzle-orm/pg-core/query-builders/select").PgSelectBase<"suppliers", { ordersCount?: import("C:/Users/hitech/code/autosync_nest/node_modules/.pnpm/drizzle-orm@0.29.0_@types+pg@8.10.7_pg@8.11...' but required in type 'Omit<import("C:/Users/hitech/code/autosync_nest/node_modules/.pnpm/drizzle-orm@0.29.0_@types+pg@8.10.7_pg@8.11.3/node_modules/drizzle-orm/pg-core/query-builders/select").PgSelectBase<"suppliers", { ordersCount?: import("C:/Users/hitech/code/autosync_nest/node_modules/.pnpm/drizzle-orm@0.29.0_@types+pg@8.10.7_pg@8.11...'. [2741]

code

    let base = this.db
      .select({
        ...getTableColumns(suppliers),
        ...((input.withCount || input.haveProducts) && {
          productsCount: sql<number>`count(distinct ${products.id})::int`.as(
            'products_count',
          ),
        }),
        ...(input.orderByOrder && {
          ordersCount: sql<number>`count(distinct ${orders.id})::int`.as(
            'orders_count',
          ),
        }),
      })
      .from(suppliers)
      .groupBy(suppliers.id);

    if (input.haveProducts || input.withCount) {
      base = base.leftJoin(products, eq(suppliers.id, products.supplierId));
    }

    if (input.haveProducts) {
     // Error on Here 
      base = base.having(({ productsCount }) => gt(productsCount!, 0));
    }

    if (input.orderByOrder) {
      return base
        .leftJoin(
          orders,
          and(
            eq(suppliers.id, orders.supplierId),
            eq(orders.affiliateId, user.affiliateId),
          ),
        )
        .orderBy(({ ordersCount, name }) => [desc(ordersCount!), name]);
    }

    return base.orderBy(suppliers.name);

Expected behavior

No response

Environment & setup

No response

@autosync-1 autosync-1 added the bug Something isn't working label Nov 15, 2023
@dankochetov
Copy link
Contributor

try reinstalling node_modules

@autosync-1
Copy link
Author

I tried but still getting Error

#0 5.400 src/suppliers/suppliers.service.ts:39:7 - error TS2741: Property 'having' is missing in type 'Omit<PgSelectBase<"suppliers", { ordersCount?: Aliased<number> | undefined; productsCount?: Aliased<number> | undefined; id: PgColumn<{ name: "id"; tableName: "suppliers"; dataType: "number"; ... 6 more ...; baseColumn: never; }, {}, {}>; ... 12 more ...; isActive: PgColumn<...>; }, ... 5 more ..., { ...; }>, "havin...' but required in type 'Omit<PgSelectBase<"suppliers", { ordersCount?: Aliased<number> | undefined; productsCount?: Aliased<number> | undefined; id: PgColumn<{ name: "id"; tableName: "suppliers"; dataType: "number"; ... 6 more ...; baseColumn: never; }, {}, {}>; ... 12 more ...; isActive: PgColumn<...>; }, ... 5 more ..., { ...; }>, "group...'.
#0 5.400
#0 5.400 39       base = base.having(({ productsCount }) => gt(productsCount!, 0));
#0 5.400          ~~~~
#0 5.400
#0 5.400   node_modules/.pnpm/drizzle-orm@0.29.0_@types+pg@8.10.7_pg@8.11.3/node_modules/drizzle-orm/pg-core/query-builders/select.d.ts:127:5
#0 5.400     127     having(having: ((aliases: this['_']['selection']) => SQL | undefined) | SQL | undefined): PgSelectWithout<this, TDynamic, 'having'>;
#0 5.400             ~~~~~~
#0 5.400     'having' is declared here.
#0 5.400
#0 5.402 Found 2 error(s).
#0 5.402
#0 5.420  ELIFECYCLE  Command failed with exit code 1.

@adicco
Copy link

adicco commented Nov 15, 2023

With Bun, I still encountered these issues after removing node_modules and reinstalling dependencies, but adding to my package.json

  "overrides": {
    "drizzle-orm": "^0.29.0"
  }

fixed the issue (Bun pm's has some known issues with harmonizing dependencies' dependencies.)

@Angelelz
Copy link
Collaborator

Can we close this as a Bun issue (with a workaround)?

@autosync-1
Copy link
Author

I'm using pnpm but getting this issue

@Angelelz
Copy link
Collaborator

Angelelz commented Dec 6, 2023

Can you provide a reproduction repo? I have this working properly

@bsShoham
Copy link

@autosync-1 what worked for me was removing the node_modules directory AND removing the lock file, and then reinstalling, overrides were not needed after that

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants