20 of the best prompts for ChatGPT for TypeScript, step by step across 4 stages. Works with ChatGPT, Claude, and Gemini.
20 of the best prompts for ChatGPT for TypeScript, step by step across 4 stages. Works with ChatGPT, Claude, and Gemini.
Published July 4, 2026
Write strongly typed TypeScript, design clean interfaces, debug type errors, and ship reliable code faster. Built across 4 distinct stages covering Type Design, Generics and Advanced Types, Real-World Patterns and more, this guide gives you one expert prompt per step so you never have to write from scratch or guess what the AI needs. The prompts work in ChatGPT, Claude, and Gemini and are designed to get usable output on the first try.
Before writing implementation, define your types and interfaces clearly.
Model TypeScript
I need to model a [DOMAIN CONCEPT] in TypeScript. The data has [DESCRIBE FIELDS AND RELATIONSHIPS]. Write a set of interfaces and types that capture this accurately, using union types, optional fields, and generics where appropriate.
Design discriminated union type
Design a discriminated union type for [STATE/EVENT SYSTEM] that has these possible states: [LIST STATES]. Each state has different data. Show me the type definition and a type guard for each variant.
Plain JavaScript object
I have this plain JavaScript object shape: [PASTE OBJECT]. Convert it to a strict TypeScript interface, infer the best types for each field, and flag any fields that should be enums or literals.
Create generic utility type
Create a generic utility type that [DESCRIBE TRANSFORMATION, E.G. "MAKES ALL NESTED PROPERTIES READONLY" OR "EXTRACTS KEYS WITH A SPECIFIC VALUE TYPE"]. Show how to apply it to this existing type: [PASTE TYPE].
Type function
I need to type a function that accepts [DESCRIBE FLEXIBLE INPUT] and returns [DESCRIBE OUTPUT]. Write the overloaded function signatures and the generic version, explaining when to use each.
Use generics to write reusable, type-safe utilities and components.
Write generic function
Write a generic function that [DESCRIBE BEHAVIOR, E.G. "GROUPS AN ARRAY BY A KEY"]. It should infer the return type correctly so callers get full autocomplete. Show usage examples with two different input types.
Create type-safe event emitter
I want to create a type-safe event emitter in TypeScript. The events are defined in this map: [PASTE EVENT MAP]. Write the class with fully typed on(), off(), and emit() methods.
Explain how
Explain how to use conditional types to build a type that [DESCRIBE CONDITION, E.G. "UNWRAPS A PROMISE TYPE" OR "FLATTENS A NESTED ARRAY TYPE"]. Show the implementation and three use cases.
Function returns different shapes
I have a function that returns different shapes based on an input flag: [DESCRIBE FUNCTION]. Rewrite it using function overloads so TypeScript knows exactly which return type to expect for each input.
Write type-safe builder pattern
Write a type-safe builder pattern for [DESCRIBE OBJECT, E.G. "A QUERY BUILDER" OR "A FORM CONFIG"]. Each method call should narrow the type so required fields must be set before build() is called.
Apply TypeScript to common real-world problems like API calls, state management, and configuration.
Fetching data
I am fetching data from this API endpoint: [DESCRIBE RESPONSE SHAPE]. Write the TypeScript types for the response, a typed fetch wrapper that handles errors, and a usage example.
Type Redux
I need to type a Redux or Zustand store for [DESCRIBE FEATURE]. Write the state interface, action types, and typed selectors. Show how to handle async actions with proper loading and error states.
Convert configuration object
Convert this configuration object to use satisfies and const assertion: [PASTE CONFIG]. Explain what each keyword adds and why this is better than a plain type annotation.
Add strict null
I want to add strict null checking to this existing codebase function: [PASTE FUNCTION]. Identify all the places where null or undefined could cause a runtime error and show how to fix each one safely.
Write typed React hook
Write a typed React hook for [DESCRIBE HOOK PURPOSE, E.G. "FETCHING AND CACHING USER DATA"]. The hook should have typed parameters, return typed values, and handle loading and error states.
Resolve type errors and upgrade untyped JavaScript to TypeScript.
Getting TypeScript error:
I am getting this TypeScript error: [PASTE ERROR MESSAGE AND RELEVANT CODE]. Explain exactly why this error occurs, what TypeScript is protecting me from, and show two ways to fix it correctly.
JavaScript file I
I have this JavaScript file I want to convert to TypeScript: [PASTE CODE]. Add types progressively, starting with function signatures, then variables, then generics. Flag anything that needs runtime validation.
TypeScript config is
My TypeScript config is too permissive and I want to enable strict mode. Here is my current tsconfig.json: [PASTE CONFIG]. Walk me through what each strict flag enables and which ones to turn on first.
Keep seeing "any"
I keep seeing "any" types in this codebase: [PASTE FILE EXCERPT]. Replace every any with a proper type, using unknown where the type is truly unknown and adding type guards where needed.
Explain these type patterns
Explain the difference between these type patterns I am confused about: [LIST PATTERNS, E.G. "INTERFACE VS TYPE ALIAS", "UNKNOWN VS ANY", "AS CONST VS SATISFIES"]. Give concrete examples showing when to use each.
Yes. Paste the full error message and the surrounding code and ChatGPT will explain what TypeScript is detecting, why it matters, and how to resolve it correctly without hiding the error.
ChatGPT handles generics, conditional types, mapped types, and template literal types well. For complex scenarios, describe the input and expected output in detail to get accurate results.
Start by asking ChatGPT to add types to individual files incrementally. Give it the file content and ask it to add types while preserving the logic, then review each change before moving to the next file.
Yes. Provide your API response shape and ChatGPT can generate typed interfaces, a fetch wrapper with error handling, and strongly typed hooks or service classes to consume the data.
Interface and type design, generic functions, utility types, discriminated unions, and migrating JavaScript to TypeScript are all areas where ChatGPT provides accurate, actionable guidance.
AI Prompts for ChatGPT for React
Build clean React components, design reusable hooks, optimize rendering, and ship production-ready UI faster..
See promptsAI Prompts for ChatGPT for API Development
Design clean APIs, write reliable endpoints, handle auth and errors properly, and document your API professionally..
See promptsAI Prompts for ChatGPT for Documentation
Write clear technical documentation, engaging READMEs, accurate API docs, and user guides that developers actually read..
See prompts