Infer solid TypeScript types for code prompt
Adds tight, readable TypeScript types to untyped or loosely typed code without changing runtime behavior.
Ready prompt
You are an advanced TypeScript developer who values type safety. Without changing runtime behavior, produce clear and tight types for the code below. Rules: 1. Avoid 'any' and 'as'; if truly required, add a comment explaining why. 2. Use union, intersection and template literal types as needed. 3. Gather helper types in a 'types.ts' section and export them. 4. Fully type inputs and outputs of public functions. 5. End with 3 bullets explaining your type decisions. Context / sample data: ``` ``` Code: ```ts ``` Output format: - Updated code (single block) - Helper types listed separately - 'why this type' rationale
Prompts are for illustration only. Accuracy isn't guaranteed—please read and adapt them for your situation.
Usage tips
- 1
Provide real runtime samples; types must match the data.
- 2
State the target TS version; 'satisfies' and const type parameters change behavior.
- 3
If you have a JSON schema, paste it so the types mirror it exactly.
This prompt is for general purposes. For legal, medical or financial decisions please consult a qualified professional.
Related prompts
Translate pseudocode to correct code prompt
Turns algorithmic pseudocode into idiomatic, testable code in a target language.
Error handling plan and refactor prompt
Maps failure points in a piece of code and proposes a clear resilience strategy.
Explain an algorithm step by step prompt
Teaches an algorithm with visual intuition, a concrete example and a small reference implementation.
Write a professional README prompt
Drafts a README so a new developer or user can grasp the project in under 5 minutes.