Beck
DTDrizzle Team
•Created by Beck on 12/28/2024 in #help
TypeScript reference cycles (`ts(7022)` errors)
Hello everyone,
I’m running into a TypeScript error that causes my table schemas to become type
any
. Here’s a simplified example illustrating the problem:
- There are two schemas, user
and team
.
- A user
may or may not have a team
(i.e., teamId
is optional).
- A team
may or may not have an owner
(i.e., ownerId
is optional).
- A team
may have many users
.
user.schema.ts
:
team.schema.ts
:
With this setup, TypeScript immediately reports these errors:
- Error on the schemas: '<schema>' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer. ts(7022)
- Error on references: Function implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions. ts(7024)
.
Question:
Is there any known workaround or recommended approach to avoid this circular reference / type inferred as any
issue and still keep references and relations in Drizzle?17 replies