sonandmjy
sonandmjy3w ago

Typescript inference help in monorepo

I have a typescript type created using the convex/values schema validator and turned into a TS type using the Infer helper but it seems to be having issues inferring it. I have a monorepo setup using turborepo and it is inferring correctly when i hover directly over the type in the backend package (1st image) but it seems to lose that inferance and becomes type any in my app (2nd image). Any ideas? Is this a limitation of convex/values because I also tested with a very simple type it seems to work crossing package boundaries but not this complex type. Thanks for the help!
export const VGetMessageDetailReturn = v.object({
...omit(Messages.withSystemFields, ["linkedMessages"]),
files: v.array(
v.object({
...omit(Files.withSystemFields, ["metadata"]),
width: v.optional(v.number()),
height: v.optional(v.number()),
blurHash: v.optional(v.string()),
fileURL: v.union(v.null(), v.string()),
thumbnail720: v.optional(
v.object({
...VThumbnail.fields,
thumbnailURL: v.optional(v.union(v.null(), v.string())),
})
),
})
),
linkedMessages: v.array(
v.union(
v.object({
...VMetaWhatsappReplyMessageLinkedMessage.fields,
message: v.union(v.object(Messages.withSystemFields), v.null()),
}),
v.object({
...VMetaWhatsappReactionMessageLinkedMessage.fields,
message: v.union(v.object(Messages.withSystemFields), v.null()),
})
)
),
});

export type TGetMessageDetailReturn = Infer<typeof VGetMessageDetailReturn>;
export const VGetMessageDetailReturn = v.object({
...omit(Messages.withSystemFields, ["linkedMessages"]),
files: v.array(
v.object({
...omit(Files.withSystemFields, ["metadata"]),
width: v.optional(v.number()),
height: v.optional(v.number()),
blurHash: v.optional(v.string()),
fileURL: v.union(v.null(), v.string()),
thumbnail720: v.optional(
v.object({
...VThumbnail.fields,
thumbnailURL: v.optional(v.union(v.null(), v.string())),
})
),
})
),
linkedMessages: v.array(
v.union(
v.object({
...VMetaWhatsappReplyMessageLinkedMessage.fields,
message: v.union(v.object(Messages.withSystemFields), v.null()),
}),
v.object({
...VMetaWhatsappReactionMessageLinkedMessage.fields,
message: v.union(v.object(Messages.withSystemFields), v.null()),
})
)
),
});

export type TGetMessageDetailReturn = Infer<typeof VGetMessageDetailReturn>;
No description
No description
1 Reply
sonandmjy
sonandmjyOP3w ago
nevermind I think it was a typescript limitation, once I made the convex backend into a compiled package and exported the .d.ts files the type inference came back

Did you find this page helpful?