-
Notifications
You must be signed in to change notification settings - Fork 3
Open
Description
When I have my TableAggregate's defined in their own and attempt to use them in another file, I get an insurmountable typescript error: Type instantiation is excessively deep and possibly infinite.
This query results in the following error:
// convex/campaigns/queries.ts
export const getSentCountForCampaign = query({
args: {
campaignId: v.id("campaigns"),
},
handler: async (ctx, args) => {
return await aggregateEmailEventsSent.count(ctx, {
namespace: args.campaignId,
bounds: {},
});
},
});
// Compilation error:
> ✖ TypeScript typecheck via `tsc` failed.
> convex | To ignore failing typecheck, use `--typecheck=disable`.
> convex/campaigns/queries.ts:77:15 - error TS2589: Type instantiation is excessively deep and possibly infinite.
> convex |
> convex | 77 bounds: {},
> convex | ~~
> convex |
> convex | Found 1 error in convex/campaigns/queries.ts:77
I can't get this two-file structure to compile without the type instantiation error:
// convex/aggregates/campaigns.ts
import { v } from "convex/values";
import { components } from "../_generated/api";
import { DataModel, Id } from "../_generated/dataModel";
import { query } from "../_generated/server";
import { TableAggregate } from "@convex-dev/aggregate";
/*
* Aggregates
*/
export const aggregateEmailEventsSent = new TableAggregate<{
Namespace: Id<"campaigns">;
Key: number;
DataModel: DataModel;
TableName: "emails";
}>(components.aggregateEmailEventsSent, {
namespace: (doc) => doc.campaignId,
sortKey: (doc) => doc._creationTime,
sumValue: () => 1,
});
// convex/campaigns/queries.ts
export const getSentCountForCampaign = query({
args: {
campaignId: v.id("campaigns"),
},
handler: async (ctx, args) => {
const forCampaign = {
namespace: args.campaignId,
bounds: {},
};
return await aggregateEmailEventsSent.count(ctx, forCampaign);
},
});
However, if both of these are in the same file, it works:
// convex/aggregates/campaigns.ts
import { v } from "convex/values";
import { components } from "../_generated/api";
import { DataModel, Id } from "../_generated/dataModel";
import { query } from "../_generated/server";
import { TableAggregate } from "@convex-dev/aggregate";
/*
* Aggregates
*/
export const aggregateEmailEventsSent = new TableAggregate<{
Namespace: Id<"campaigns">;
Key: number;
DataModel: DataModel;
TableName: "emails";
}>(components.aggregateEmailEventsSent, {
namespace: (doc) => doc.campaignId,
sortKey: (doc) => doc._creationTime,
sumValue: () => 1,
});
export const getSentCountForCampaign = query({
args: {
campaignId: v.id("campaigns"),
},
handler: async (ctx, args) => {
const forCampaign = {
namespace: args.campaignId,
bounds: {},
};
return await aggregateEmailEventsSent.count(ctx, forCampaign);
},
});
Notably, this has been a little fickle. I got it to work in in the first way (two files) after deleting and regenerating the Convex code, in addition to changing this line (the error occurs no matter what when I try to inline the Bounds
object):
This works in both cases:
const forCampaign = {
namespace: args.campaignId,
bounds: {},
};
return await aggregateEmailEventsSent.count(ctx, forCampaign);
This works only if defined in the same file as the aggregate:
return await aggregateEmailEventsSent.count(ctx, {
namespace: args.campaignId,
bounds: {},
});
Niall-Kenny
Metadata
Metadata
Assignees
Labels
No labels