
Description
Does your checkout flow sometimes show a "Pay" button while a payment is already in progress? Does a signup skip a step after the user goes back? This free prompt for ChatGPT writes the TypeScript code for your process so that impossible steps are rejected as you write the code, before you even run the application. Technically, it produces a TypeScript state machine: code that describes each step and the only transitions allowed between them. You also receive its tests. The prompt is written in French and works in any language model that understands French.
Who is it for?
• Freelance frontend developers building shops, forms or signup flows.
• Small tech teams in small and medium businesses who want to make their business logic more reliable without adding a library.
What you get
• The assumptions made and the inconsistencies spotted in your description.
• A table of states, a table of events and a table of transitions with their conditions, followed by the list of forbidden transitions and the reason for each.
• A strict TypeScript file with no dependencies. States are described with a discriminated union, the allowed events are defined for each state, the transition function is pure, and an exhaustiveness check is ensured with "never".
• A Vitest or Jest test file covering allowed transitions, forbidden transitions (at runtime and at compile time), conditions and a full scenario.
• Advice on plugging the machine into React, Vue, Svelte or Angular.
How to use it
• Copy the prompt into ChatGPT.
• Fill in the fields: process, steps, events, business rules, data for each step, testing tool, UI framework.
• Write "to be defined" wherever you are unsure: an assumption will be made and flagged.
• Send it, then paste the two files into your project and run the tests.
Example of the expected result
For a checkout flow, you get for instance the states "cart", "address entered", "payment in progress", "paid", "shipped" and "cancelled". The "cancel" event is only accepted from the states where cancelling makes sense. Trying to send it from "shipped" causes a compile error, checked by a test. If you were looking for a TypeScript state machine example, here you get one built for your own process.
Limits
The code is generated by an AI: review it and run the tests before putting it into production. The front-end state machine does not replace server-side validation, which remains essential for payments and orders. Business rules you did not provide are assumptions to be confirmed.
Original listing published on La Prompterie: https://www.prompterie.com/en/prompt/commande-ou-inscription-sans-etape-impossible-code-typescript-et-ses-tests
Details
Words
865
Tokens
~1125
AI Model
ChatGPT
Views
0
Language
FR
