Skip to content

Types for your answers

npx seaforms pull writes a .seaforms.d.ts beside each form’s file. For the contact form, src/forms/contact.seaforms.d.ts:

src/forms/contact.seaforms.d.ts
// Types for the answers to contact.seaforms.json, revision 3.
// Made by the Seaforms CLI. Don't edit it: pull the form again after you publish a change.
/**
* A submission's answers, keyed by question, as webhooks and the Seaforms API send them. An answer
* is optional when the question can be left blank or only shows sometimes. A webhook set to send
* only some questions leaves the others out.
*/
export interface ContactAnswers {
/** Name */
name: string;
/** Email */
email: string;
/** What’s it about? */
topic: "sales" | "support" | "press" | "something-else";
/** Message */
message: string;
}
/** Which thank-you showed: `ending` in `onSubmitted`. */
export type ContactEnding = "thanks";
/** The form's steps: `stepId` in `onStep`. */
export type ContactStep = "get-in-touch";

Don’t edit it: pull again after you publish a change, and it’s written again.

  • <Name>Answers: a submission’s answers, keyed by each question’s key, as webhooks and the API send them. An answer is optional when the question can be left blank or only shows sometimes. Tick boxes, consent and quantities are always there when they always show.
  • <Name>Ending: which thank-you showed: ending in onSubmitted and in a submission.
  • <Name>Step: each step’s ID: stepId in onStep.

The name comes from the form’s: contact gives ContactAnswers, project-enquiry gives ProjectEnquiryAnswers.

app/api/seaforms/route.ts
import type { ContactAnswers } from "@/forms/contact.seaforms";
const answers = event.data.answers as ContactAnswers;
if (answers.topic === "sales") {
// …
}

A webhook set to send only some questions leaves the others out, so treat its answers as Partial<ContactAnswers>.

If you saved a form’s file from the app instead of pulling it, write its types with types. It needs no sign-in and no network:

Terminal window
npx seaforms types src/forms

The types follow our logic engine itself: our tests check them against hundreds of real runs of every template, and compile them with TypeScript.

Was this helpful?

Your answer goes straight to the person who wrote it.

Thanks. We read every note and update the article.

Thanks, that helps us keep these useful.

ChatGPT is a trademark of OpenAI, and Claude and Claude Code are trademarks of Anthropic. Other product names and logos belong to their owners. None of them makes or endorses Seaforms. Trademarks