#Typescript error in table definition

8 messages · Page 1 of 1 (latest)

uncut star
#

Getting this typescript error in a monorepo setup but I'm not sure where i should even start looking to debug this. Would you have any clue?

Type 'TableDefinition<VObject<{ parentInternalNoteId?: Id<"internalNotes"> | undefined; parentMessageId?: Id<"messages"> | undefined; organizationId: Id<"organizations">; channelId: Id<"channels">; ... 4 more ...; sentFrom: Id<...>; }, { ...; }, "required", "organizationId" | ... 9 more ... | "data.comment">, { ...; }, {}...' is not assignable to type 'TableDefinition<Validator<any, any, any>, {}, {}, {}>'.
  Types have separate declarations of a private property 'indexes'.ts(2322)
lilac fableBOT
#

Hi @uncut star. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

This TypeScript error:

Type 'TableDefinition<VObject<...>>' is not assignable to type 'TableDefinition<Validator<any, any, any>, {}, {}, {}>'.
  Types have separate declarations of a private property 'indexes'.ts(2322)

is a classic TypeScript issue that often arises in monorepo or multi-package setups when you have multiple copies of the Convex package (or any package that defines classes with private/protected members) installed in different parts of your project. TypeScript treats classes with private/protected members as incompatible if they come from different package instances, even if their code is identical. This is because the private members are considered unique to each package instance.

Where to start debugging:

  • Check for duplicate Convex installations: Make sure that all parts of your monorepo are using the same instance of the Convex package. If you have multiple node_modules folders (e.g., one in the root and one in a package), you might have multiple copies of Convex.
  • Use a single version: Ensure that all packages reference the same version of Convex in their package.json.
  • Hoist dependencies: If you use a monorepo tool like Yarn Workspaces or pnpm, make sure dependencies are hoisted to the root to avoid duplication.
  • Check your TypeScript config: Make sure your tsconfig.json is set up to resolve modules consistently across your monorepo.

This is a well-known TypeScript quirk and not specific to Convex, but it can be especially confusing with class-based APIs like Convex's TableDefinition that use private members for type safety. For more on this, see the Convex API docs on TableDefinition.

#

If you need more details on how to structure your schema and table definitions to avoid type issues, see the advice on modular schemas and imports in this Discord thread.

Summary:
This is almost certainly a duplicate dependency issue. Unify your Convex package versions and ensure only one copy is installed and used throughout your monorepo. That should resolve the error.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:

#

@uncut star Kapa.ai is still learning and improving, please let me know how I did by reacting below.

uncut star
#

@lilac fable ok this is my npm list, do i have to dedup installations?

├─┬ @untitled-bookings/backend@ -> ./packages/backend
│ ├─┬ @convex-dev/agent@0.1.1
│ │ └── convex@1.24.3 deduped
│ ├─┬ @convex-dev/aggregate@0.1.20
│ │ └── convex@1.18.2 deduped
│ ├─┬ @convex-dev/auth@0.0.86 invalid: "^0.0.80" from packages/backend
│ │ └── convex@1.24.3 deduped
│ ├─┬ @convex-dev/migrations@0.2.4
│ │ └── convex@1.18.2 deduped
│ ├─┬ @convex-dev/r2@0.3.0
│ │ ├─┬ @convex-dev/action-retrier@0.1.6
│ │ │ └── convex@1.18.2 deduped
│ │ └── convex@1.24.3 deduped
│ ├─┬ convex-helpers@0.1.89
│ │ └── convex@1.18.2 deduped
│ ├─┬ convex-test@0.0.35
│ │ └── convex@1.18.2 deduped
│ └── convex@1.24.3
└─┬ @untitled-bookings/web@ -> ./apps/web
├─┬ @convex-dev/auth@0.0.80
│ └── convex@1.18.2 deduped
├─┬ @convex-dev/react-query@0.0.0-alpha.8
│ └── convex@1.18.2 deduped
└── convex@1.18.2

lilac fableBOT
#

Let me check the knowledge base for you again. One moment! :books:

#

Yes, you should deduplicate your Convex installations. Your npm list shows that you have multiple versions of the convex package installed in your monorepo (1.24.3 and 1.18.2). This is a common cause of the TypeScript error you’re seeing, especially with types involving classes that have private members, like TableDefinition. TypeScript treats these as incompatible if they come from different package instances.

To resolve this, ensure that all packages in your monorepo depend on the same version of convex. Update your package.json files so that every dependency requiring convex uses the same version (preferably the latest one you want to use, e.g., 1.24.3). Then, run a deduplication command such as:

npm dedupe

or, if you use pnpm or yarn, use their respective deduplication/hoisting features.

This approach is supported by the general advice in the Convex community and Discord threads, where similar issues have been resolved by unifying dependency versions and ensuring only one copy of Convex is installed throughout the monorepo. This will help avoid the TypeScript type incompatibility errors you’re experiencing due to multiple Convex versions being present in your dependency tree see related discussion.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: