-
Notifications
You must be signed in to change notification settings - Fork 88
Closed
Description
Hi, thanks for the awesome package,
I could not find a way to infer a typescript type from a schema, that I could use elsewhere in my app to help build the correct object to insert in my repository.
For example considering this schema:
export const messageSchema = new Schema("message", {
name: { type: "text" },
category: { type: "string" },
lastUpdated: { type: "date" },
lastUpdater: { type: "string" },
});I could totally write the typescript type myself and export it like:
export type MessageSchema = {
name: string,
category: string,
lastUpdated: date,
lastUpdater: string,
};But if I update the schema I have to update the type.
Could we find a way to infer the typescript type from a Schema so its always sync with something like:
export const messageSchema = new Schema("message", {
name: { type: "text" },
category: { type: "string" },
lastUpdated: { type: "date" },
lastUpdater: { type: "string" },
});
export type MessageSchema = Schema.infer<typeof messageSchema> // {name: string; category: string; lastUpdated: string; lastUpdater: string}This is inspired from the Zod type inference https://zod.dev/?id=type-inference
Thanks :)
Metadata
Metadata
Assignees
Labels
No labels