Typescript validation error when using groupBy
See original GitHub issueBug description
Using groupBy and not specifying a fixed value for the having attribute results in several typescript validation errors. Errors occur both when assigned as “Prisma.CategoryGroupByArgs” and “any”.
Expected behavior
No validation error occurs
Environment & setup
- OS: Mac OS
- Database: PostgreSQL
- Node.js version: 14.15.4
- Prisma version: 2.20.1
Error
`src/api/categories/categories.service.ts:53:18 - error TS2615: Type of property ‘AND’ circularly references itself in mapped type ‘{ [K in keyof { AND?: Enumerable<CategoryScalarWhereWithAggregatesInput>; OR?: Enumerable<CategoryScalarWhereWithAggregatesInput>; … 15 more …; parentId?: number | IntNullableWithAggregatesFilter; }]: Or<…> extends 1 ? { …; }[K] extends infer TK ? GetHavingFields<…> : never : {} extends FieldPaths<…> ? n…’.
53 return await this.prisma.category.groupBy(data); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/api/categories/categories.service.ts:53:18 - error TS2615: Type of property ‘NOT’ circularly references itself in mapped type ‘{ [K in keyof { AND?: Enumerable<CategoryScalarWhereWithAggregatesInput>; OR?: Enumerable<CategoryScalarWhereWithAggregatesInput>; … 15 more …; parentId?: number | IntNullableWithAggregatesFilter; }]: Or<…> extends 1 ? { …; }[K] extends infer TK ? GetHavingFields<…> : never : {} extends FieldPaths<…> ? n…’.
53 return await this.prisma.category.groupBy(data); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/api/categories/categories.service.ts:53:18 - error TS2615: Type of property ‘OR’ circularly references itself in mapped type ‘{ [K in keyof { AND?: Enumerable<CategoryScalarWhereWithAggregatesInput>; OR?: Enumerable<CategoryScalarWhereWithAggregatesInput>; … 15 more …; parentId?: number | IntNullableWithAggregatesFilter; }]: Or<…> extends 1 ? { …; }[K] extends infer TK ? GetHavingFields<…> : never : {} extends FieldPaths<…> ? n…’.
53 return await this.prisma.category.groupBy(data); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/api/categories/categories.service.ts:53:47 - error TS2345: Argument of type ‘CategoryGroupByArgs’ is not assignable to parameter of type ‘({ where?: CategoryWhereInput; orderBy?: Enumerable<CategoryOrderByInput>; by: (“id” | “createdAt” | “updatedAt” | “published” | … 10 more … | “parentId”)[]; … 7 more …; max?: CategoryMaxAggregateInputType; } & { …; } & Error: Field "${any}" used in "having" needs to be provided in "by".
) | ({ …; } & …’.
Type ‘CategoryGroupByArgs’ is not assignable to type ‘{ where?: CategoryWhereInput; orderBy?: Enumerable<CategoryOrderByInput>; by: (“id” | “createdAt” | “updatedAt” | “published” | … 10 more … | “parentId”)[]; … 7 more …; max?: CategoryMaxAggregateInputType; } & { …; } & […]’.
Type ‘CategoryGroupByArgs’ is not assignable to type ‘{ orderBy: Enumerable<CategoryOrderByInput>; }’.
Property ‘orderBy’ is optional in type ‘CategoryGroupByArgs’ but required in type ‘{ orderBy: Enumerable<CategoryOrderByInput>; }’.
53 return await this.prisma.category.groupBy(data);`
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (4 by maintainers)
Top GitHub Comments
Same issue here, with global and local typescript versions both being 4.2.4. Behaviour is the same as for @DennieMello.
Can you please reopen the issue and investigate?
Closing in favor of https://github.com/prisma/prisma/issues/7183