20 of the best prompts for Claude for TypeScript, step by step across 4 stages. Works with ChatGPT, Claude, and Gemini.
20 of the best prompts for Claude for TypeScript, step by step across 4 stages. Works with ChatGPT, Claude, and Gemini.
Getting Claude for TypeScript right takes more than a single prompt. This 4-stage guide covers Type Design, Generics and Advanced Types, Practical Patterns, and more, breaking the whole process into focused steps where each prompt builds on the last. Write strongly typed TypeScript, untangle complex type errors, design clean interfaces, and migrate JavaScript codebases confidently. Every prompt is optimized and runs in ChatGPT, Claude, and Gemini.
Model your domain accurately with interfaces, unions, and utility types.
Data has
I need to model [DESCRIBE DOMAIN CONCEPT] in TypeScript. The data has [DESCRIBE FIELDS AND RELATIONSHIPS]. Write a set of interfaces and types, using union types, optional fields, and generics where they add real value.
Design discriminated union
Design a discriminated union for [STATE MACHINE OR EVENT TYPE]. It should have these variants: [LIST]. Show the type definition and a type guard for each variant.
Plain JavaScript object:
I have this plain JavaScript object: [PASTE OBJECT]. Convert it to a strict TypeScript interface. Infer the best type for each field and flag anything that should be an enum or literal type.
Create utility type
Create a utility type that [DESCRIBE TRANSFORMATION, E.G. "MAKES ALL NESTED PROPERTIES OPTIONAL" OR "EXTRACTS KEYS WHOSE VALUES ARE STRINGS"]. Show how to apply it to an existing type.
Write overload signatures
I need a type for a function that behaves differently based on its arguments: [DESCRIBE THE OVERLOADS]. Write the overload signatures and explain when TypeScript requires this vs when a union return type works.
Write reusable, type-safe utilities using generics and conditional types.
Write generic function
Write a generic function that [DESCRIBE BEHAVIOR, E.G. "GROUPS AN ARRAY BY A KEY"]. The return type should infer correctly so callers get full autocomplete. Show two usage examples.
Build type-safe event emitter
Build a type-safe event emitter where events are defined in this map: [PASTE EVENT MAP]. The on(), off(), and emit() methods should be fully typed.
Explain conditional types
Explain conditional types with a practical example: [DESCRIBE USE CASE, E.G. "UNWRAP A PROMISE TYPE" OR "FLATTEN A NESTED ARRAY"]. Show the implementation and three real-world applications.
Write builder pattern
Write a builder pattern for [DESCRIBE OBJECT] where each method call narrows the type — so TypeScript enforces that required fields are set before .build() is callable.
Use satisfies operator
I want to use the satisfies operator for this config object: [PASTE CONFIG]. Explain what satisfies adds compared to a plain type annotation and when to prefer it over as const.
Apply TypeScript to everyday problems: API calls, forms, state, and config.
Fetch data
I fetch data from this API: [DESCRIBE RESPONSE SHAPE]. Write the TypeScript types, a typed fetch wrapper with error handling, and a typed hook or service function to consume it.
Add strict TypeScript
Add strict TypeScript to this Redux or Zustand store: [PASTE STORE]. Type the state, actions, and selectors. Handle async actions with proper loading and error state types.
Write typed React form
Write a typed React form for [DESCRIBE FIELDS AND VALIDATION RULES]. Use React Hook Form with Zod schema validation so the form is end-to-end type safe.
Add TypeScript
I want to add TypeScript to this Node.js Express route: [PASTE ROUTE]. Type the request params, query, body, and response. Show how to create a typed middleware wrapper.
Convert untyped configuration
Convert this untyped configuration to strict TypeScript: [PASTE CONFIG]. Add proper types, use const assertions or satisfies where appropriate, and explain why each change matters.
Resolve type errors and move JavaScript codebases to TypeScript.
TypeScript error:
I have this TypeScript error: [PASTE FULL ERROR AND CODE]. Explain exactly what TypeScript is detecting, what it protects against, and show two correct ways to fix it.
Convert JavaScript file
Convert this JavaScript file to TypeScript: [PASTE FILE]. Add types progressively from function signatures outward, flag anything that needs runtime validation, and avoid using any.
Enable strict mode
I want to enable strict mode in this project. My current tsconfig: [PASTE]. Walk me through what each strict flag enables, the order to turn them on, and the most common errors each will surface.
File is full
This file is full of any types: [PASTE EXCERPT]. Replace every any with a proper type. Use unknown where the type is truly unknown and add type guards where narrowing is needed.
Explain practical difference
Explain the practical difference between these TypeScript patterns I keep mixing up: [LIST PAIRS, E.G. "INTERFACE VS TYPE ALIAS", "AS CONST VS SATISFIES", "UNKNOWN VS ANY"].
Yes. Paste the error message and surrounding code and Claude will explain what TypeScript detected, why it matters, and how to fix it correctly without suppressing the error.
Claude handles conditional types, mapped types, template literal types, and utility type composition well. For complex scenarios, describe the input and expected output clearly for the best results.
Yes. Claude can add types incrementally to individual files, starting from function signatures and moving outward, flagging anything that needs runtime validation along the way.
Interface and type design, discriminated unions, generic functions, utility types, strict mode migration, and typing real-world patterns like API clients and React hooks are all strong areas.
Yes. Provide the API response shape and Claude will generate typed interfaces, a typed fetch wrapper with error handling, and a service or hook to consume the data safely.
AI Prompts for Claude for React
Build clean React components, design reusable hooks, fix bugs faster, and ship production-quality UI with confidence..
See promptsAI Prompts for Claude for JavaScript
Write cleaner JavaScript, understand modern language features, debug faster, and build reliable Node.js applications..
See promptsAI Prompts for Claude for Coding
Claude is particularly strong for code that requires reasoning about complex logic, understanding large codebases, and writing code that is both correct and readable.
See prompts