Type error: Type parameter has a circular constraint

Hi all! Trying to figure out this error I'm getting when running next build. Thought I'd drop it here in case anyone else has run into it or has any tips for debugging:
- info Checking validity of types...
Failed to compile.

../../node_modules/drizzle-orm/column.d-04875079.d.ts:273:11
Type error: Type parameter 'K' has a circular constraint.

271 | } & TUpdate>;
272 | type Simplify<T> = {
> 273 | [K in keyof T]: T[K];
| ^
274 | } & {};
275 | type SimplifyMappedType<T> = [T] extends [unknown] ? T : never;
276 | type ShallowRecord<K extends keyof any, T> = SimplifyMappedType<{
- info Checking validity of types...
Failed to compile.

../../node_modules/drizzle-orm/column.d-04875079.d.ts:273:11
Type error: Type parameter 'K' has a circular constraint.

271 | } & TUpdate>;
272 | type Simplify<T> = {
> 273 | [K in keyof T]: T[K];
| ^
274 | } & {};
275 | type SimplifyMappedType<T> = [T] extends [unknown] ? T : never;
276 | type ShallowRecord<K extends keyof any, T> = SimplifyMappedType<{
12 Replies
Ransom
RansomOP17mo ago
So, I think this is related to the zod integration, but still exploring.
swessel
swessel16mo ago
have similar issues. Also, some strange issues relating to zod happen. For example a schema like z.object({ key: z.string() }) becomes a type of { key?: string} - the object keys become optional in type definitions.
Ransom
RansomOP16mo ago
Your issue with keys being optional is likely due to not having strict: true set in your tsconfig. Can you check that?
Angelelz
Angelelz16mo ago
Might as well throw in strickNullCheck in your tsconfig.
swessel
swessel16mo ago
👍 Ohhh, thank's! Yes, that fixed the issue. In addition to you'r mentioned issue, I also get:
node_modules/drizzle-orm/column.d-04875079.d.ts:465:22
465 type TableConfig$2 = TableConfig$3<MySqlColumn>;
~~~~~~~~~~~~~~~~~~~~~~~~~~
Circularity originates in type at this location.

node_modules/drizzle-orm/select.types.d-b0925107.d.ts:298:15 - error TS2420: Class 'MySqlDelete<TTable, TQueryResult, TPreparedQueryHKT>' incorrectly implements interface 'SQLWrapper'.
Property 'getSQL' is missing in type 'MySqlDelete<TTable, TQueryResult, TPreparedQueryHKT>' but required in type 'SQLWrapper'.

298 declare class MySqlDelete<TTable extends AnyMySqlTable, TQueryResult extends QueryResultHKT, TPreparedQueryHKT extends PreparedQueryHKTBase> extends QueryPromise<QueryResultKind<TQueryResult, never>> implements SQLWrapper {
~~~~~~~~~~~

node_modules/drizzle-orm/column.d-04875079.d.ts:87:5
87 getSQL(): SQL;
~~~~~~~~~~~~~~
'getSQL' is declared here.
node_modules/drizzle-orm/column.d-04875079.d.ts:465:22
465 type TableConfig$2 = TableConfig$3<MySqlColumn>;
~~~~~~~~~~~~~~~~~~~~~~~~~~
Circularity originates in type at this location.

node_modules/drizzle-orm/select.types.d-b0925107.d.ts:298:15 - error TS2420: Class 'MySqlDelete<TTable, TQueryResult, TPreparedQueryHKT>' incorrectly implements interface 'SQLWrapper'.
Property 'getSQL' is missing in type 'MySqlDelete<TTable, TQueryResult, TPreparedQueryHKT>' but required in type 'SQLWrapper'.

298 declare class MySqlDelete<TTable extends AnyMySqlTable, TQueryResult extends QueryResultHKT, TPreparedQueryHKT extends PreparedQueryHKTBase> extends QueryPromise<QueryResultKind<TQueryResult, never>> implements SQLWrapper {
~~~~~~~~~~~

node_modules/drizzle-orm/column.d-04875079.d.ts:87:5
87 getSQL(): SQL;
~~~~~~~~~~~~~~
'getSQL' is declared here.
node_modules/drizzle-orm/select.types.d-b0925107.d.ts:385:15 - error TS18052: Non-abstract class 'MySqlSelect<TTableName, TSelection, TSelectMode, TPreparedQueryHKT, TNullabilityMap>' does not implement all abstract members of 'MySqlSelectQueryBuilder<MySqlSelectHKT, TTableName, TSelection, TSelectMode, TNullabilityMap>'

385 declare class MySqlSelect<TTableName extends string | undefined, TSelection, TSelectMode extends SelectMode, TPreparedQueryHKT extends PreparedQueryHKTBase, TNullabilityMap extends Record<string, JoinNullability> = TTableName extends string ? Record<TTableName, 'not-null'> : {}> extends MySqlSelectQueryBuilder<MySqlSelectHKT, TTableName, TSelection, TSelectMode, TNullabilityMap> {
~~~~~~~~~~~

node_modules/drizzle-orm/select.types.d-f5caa4d6.d.ts:9:14
9 abstract getSQL(): SQL;
~~~~~~
Non-abstract class 'MySqlSelect<TTableName, TSelection, TSelectMode, TPreparedQueryHKT, TNullabilityMap>' does not implement inherited abstract member 'getSQL' from class 'MySqlSelectQueryBuilder<MySqlSelectHKT, TTableName, TSelection, TSelectMode, TNullabilityMap>'.
node_modules/drizzle-orm/select.types.d-b0925107.d.ts:385:15 - error TS18052: Non-abstract class 'MySqlSelect<TTableName, TSelection, TSelectMode, TPreparedQueryHKT, TNullabilityMap>' does not implement all abstract members of 'MySqlSelectQueryBuilder<MySqlSelectHKT, TTableName, TSelection, TSelectMode, TNullabilityMap>'

385 declare class MySqlSelect<TTableName extends string | undefined, TSelection, TSelectMode extends SelectMode, TPreparedQueryHKT extends PreparedQueryHKTBase, TNullabilityMap extends Record<string, JoinNullability> = TTableName extends string ? Record<TTableName, 'not-null'> : {}> extends MySqlSelectQueryBuilder<MySqlSelectHKT, TTableName, TSelection, TSelectMode, TNullabilityMap> {
~~~~~~~~~~~

node_modules/drizzle-orm/select.types.d-f5caa4d6.d.ts:9:14
9 abstract getSQL(): SQL;
~~~~~~
Non-abstract class 'MySqlSelect<TTableName, TSelection, TSelectMode, TPreparedQueryHKT, TNullabilityMap>' does not implement inherited abstract member 'getSQL' from class 'MySqlSelectQueryBuilder<MySqlSelectHKT, TTableName, TSelection, TSelectMode, TNullabilityMap>'.
Errors Files
1 node_modules/drizzle-orm/column.d-04875079.d.ts:273
2 node_modules/drizzle-orm/select.types.d-b0925107.d.ts:298
Errors Files
1 node_modules/drizzle-orm/column.d-04875079.d.ts:273
2 node_modules/drizzle-orm/select.types.d-b0925107.d.ts:298
Ransom
RansomOP16mo ago
I was finally able to move past this error (so far) - by setting skipLibCheck on my NextJs project. It's obviously not ideal, but that's what I get for building a giant mono-repo with Nx.
swessel
swessel16mo ago
Thanks, this worked for me too. Yes, it's not ideal, but it is a workaround for now. But now I'm able to build again at all. I think it will be fixed in one of the next releases.
Ransom
RansomOP16mo ago
What makes you say that? Is there a GH issue I can follow? Just curious, were you using NextJS or in a monorepo? I’m just curious what the cause is
swessel
swessel16mo ago
I'm using a monorepo without nextjs my setup: "typescript": "^5.1.6" "mysql2": "^3.6.0", "drizzle-orm": "^0.28.2", "zod": "^3.21.4" and tried with node 18 and 20 I did not open a github issue yet, as I was come across this thread here via google
Ransom
RansomOP16mo ago
Ok, just curious! Glad we’re both up and running again
Zamiel
Zamiel16mo ago
Note that skipLibCheck is a common optimization setting that is turned on in monorepos, since you generally trust that the libraries that you are using are not going to be released with any type errors in them.
Dan
Dan16mo ago
skipLibCheck should typically be enabled in your projects. You don't need to check the libraries' internal types, they may often break because of TS version mismatch, even though the public API will work fine. The most common use case is when the library was built using a newer/different version of TS than the one used in your project.
Want results from more Discord servers?
Add your server