88 * @module
99 */
1010
11- import { AnyDataModel } from "convex/server" ;
11+ import type {
12+ DataModelFromSchemaDefinition ,
13+ DocumentByName ,
14+ TableNamesInDataModel ,
15+ SystemTableNames ,
16+ } from "convex/server" ;
1217import type { GenericId } from "convex/values" ;
13-
14- /**
15- * No `schema.ts` file found!
16- *
17- * This generated code has permissive types like `Doc = any` because
18- * Convex doesn't know your schema. If you'd like more type safety, see
19- * https://docs.convex.dev/using/schemas for instructions on how to add a
20- * schema file.
21- *
22- * After you change a schema, rerun codegen with `npx convex dev`.
23- */
18+ import schema from "../schema.js" ;
2419
2520/**
2621 * The names of all of your Convex tables.
2722 */
28- export type TableNames = string ;
23+ export type TableNames = TableNamesInDataModel < DataModel > ;
2924
3025/**
3126 * The type of a document stored in Convex.
27+ *
28+ * @typeParam TableName - A string literal type of the table name (like "users").
3229 */
33- export type Doc = any ;
30+ export type Doc < TableName extends TableNames > = DocumentByName <
31+ DataModel ,
32+ TableName
33+ > ;
3434
3535/**
3636 * An identifier for a document in Convex.
@@ -42,8 +42,10 @@ export type Doc = any;
4242 *
4343 * IDs are just strings at runtime, but this type can be used to distinguish them from other
4444 * strings when type checking.
45+ *
46+ * @typeParam TableName - A string literal type of the table name (like "users").
4547 */
46- export type Id < TableName extends TableNames = TableNames > =
48+ export type Id < TableName extends TableNames | SystemTableNames > =
4749 GenericId < TableName > ;
4850
4951/**
@@ -55,4 +57,4 @@ export type Id<TableName extends TableNames = TableNames> =
5557 * This type is used to parameterize methods like `queryGeneric` and
5658 * `mutationGeneric` to make them type-safe.
5759 */
58- export type DataModel = AnyDataModel ;
60+ export type DataModel = DataModelFromSchemaDefinition < typeof schema > ;
0 commit comments