20 of the best prompts for enforcing TypeScript strict mode, step by step across 4 stages. Works with ChatGPT, Claude, and Gemini.
20 of the best prompts for enforcing TypeScript strict mode, step by step across 4 stages. Works with ChatGPT, Claude, and Gemini.
Published June 28, 2026
Most people try to use AI for Enforcing TypeScript Strict Mode with a single vague prompt and get generic results. This guide takes a different approach: 4 targeted stages, from Diagnose the Wall through Prevent Recurrence, each with a prompt that gives the AI exactly the context it needs. Claude Code bypasses TypeScript type safety by using any types, incorrect assertions, or ts-ignore comments, leading to potential runtime errors. This undermines the reliability and maintainability of your codebase. These prompts help you diagnose, fix, verify, and prevent such violations effectively. Works with ChatGPT, Claude, and Gemini.
Identify where TypeScript strict mode rules are being violated.
Check TypeScript Config
Please review the contents of the tsconfig.json file for a TypeScript project. Confirm whether strict mode is enabled and provide a detailed overview of the current settings. Highlight any deviations from strict mode, explaining the implications of these settings on type safety and code quality. Additionally, suggest any necessary adjustments to ensure strict mode is fully enabled, and format your response in a clear, organized manner.
Identify Any Usages
Please scan the codebase for any occurrences of type usages in TypeScript files. For each instance found, provide a detailed list that includes the specific type being used, the file name where it appears, and the line number of each occurrence. Additionally, summarize any potential issues or conflicts related to TypeScript's strict mode that may arise from these usages. Format the output as a structured report for easy review.
Locate Incorrect Assertions
Please analyze the provided codebase for any incorrect type assertions that may violate TypeScript's strict mode. Generate a detailed report that includes a list of specific lines and corresponding files where these incorrect assertions are found. Additionally, provide a brief explanation of why each assertion is considered incorrect and suggest potential corrections to ensure compliance with strict type checking. Format the output as a structured table for easy reference.
Find ts-ignore Comments
Please scan the codebase for any instances of ts-ignore comments. For each occurrence, provide the exact location in the code, including the file name and line number. Additionally, summarize the reasons given for using each ts-ignore comment, and suggest potential solutions or alternatives that could address the underlying issues without the need for ignoring TypeScript's strict mode checks. Format the report as a detailed list for easy reference.
Analyze TypeScript Errors
Please analyze the TypeScript code provided and identify all current errors, specifically focusing on type safety violations. For each error, provide a brief description of the issue, the line number where it occurs, and suggestions for how to resolve it. Additionally, categorize the errors into different types, such as 'Type Mismatch,' 'Missing Type Annotations,' and 'Excessive Type Assertions.' Present the findings in a clear, organized format that I can easily reference for debugging.
Address each identified violation to restore strict type safety.
Remove Any Types
Identify all instances of 'any' type usage in the provided TypeScript code. For each occurrence, suggest a more specific type that accurately represents the data being handled. Provide refactored code snippets that replace the 'any' types with these specific types, ensuring that the code remains functional and adheres to TypeScript's strict mode. Additionally, explain the reasoning behind the chosen specific types for clarity.
Correct Type Assertions
Identify the lines of code with incorrect type assertions in the provided TypeScript snippet. For each incorrect assertion, replace it with the appropriate type and show the corrected lines of code. Ensure that the changes maintain the functionality of the code while adhering to TypeScript's strict mode requirements. Provide a brief explanation for each correction made, highlighting why the new type is more suitable.
Eliminate ts-ignore Comments
Please review the following TypeScript code and remove any instances of ts-ignore comments. Identify the underlying type issues that necessitated these comments and resolve them appropriately. After making the necessary adjustments, provide the updated code without any ts-ignore comments, ensuring that it adheres to TypeScript's strict mode. Include comments explaining the changes made and how the type issues were resolved.
Refactor Problematic Code
Identify the sections of code that violate TypeScript's strict mode and provide a detailed refactoring for each section. Ensure that the refactored code adheres to type safety principles and eliminates any type-related errors. Include comments explaining the changes made and the reasoning behind them. Format the output to clearly separate each refactored section, and provide examples of how the new code improves type safety compared to the original.
Update TypeScript Definitions
Please update or create TypeScript definitions for the following codebase: [INSERT CODEBASE OR MODULE NAME]. Ensure that the definitions are comprehensive and prevent any potential type issues that may arise in strict mode. Provide the new or updated definitions in a clear format, highlighting any changes made and explaining the reasoning behind them. Additionally, include examples of how these definitions can be used effectively in the code.
Ensure all type safety violations have been resolved and strict mode is enforced.
Run TypeScript Check
Please run a TypeScript check on the provided code to ensure there are no type safety errors present. Display the output clearly, including any warnings or errors that are identified, along with their corresponding line numbers and descriptions. Additionally, summarize any potential improvements or changes that could enhance type safety in the code. Ensure the results are formatted in a way that is easy to read and understand.
Validate TypeScript Config
Please validate the TypeScript configuration in the tsconfig.json file. Ensure that strict mode is enabled and all relevant settings are correctly configured. Specifically, check for the following options: strict, noImplicitAny, strictNullChecks, and strictFunctionTypes. Provide a summary of the current configuration and indicate any adjustments needed to fully comply with TypeScript's strict mode requirements.
Review Code Changes
Please review the following code changes made to enforce TypeScript strict mode. List all modifications that were implemented, ensuring that every instance of any types and ts-ignore comments has been removed. Additionally, provide a brief explanation of how each change contributes to adhering to strict mode guidelines and improving type safety in the codebase. Format your response as a detailed report with clear sections for each change, including code snippets where applicable.
Test Application Functionality
Please run the application and verify that all functionality is working correctly after the recent fix. Document any issues you encounter during the testing process, including specific error messages, unexpected behaviors, or any features that do not perform as intended. Provide a detailed report summarizing your findings, including steps to reproduce any issues and the expected versus actual outcomes for each functionality tested.
Confirm Type Safety
Please review the following sample of refactored code for adherence to TypeScript's strict mode type safety. Analyze the code for any potential type errors, improper type annotations, or areas where type safety could be improved. Provide detailed feedback on compliance, including specific examples from the code that illustrate any issues found, and suggest possible corrections or improvements to enhance type safety. Format your response in a structured manner, highlighting key points and recommendations.
Implement safeguards to maintain TypeScript strict mode adherence.
Create CLAUDE.md Rule
Draft a new rule for a document titled CLAUDE.md that enforces strict type safety in TypeScript. The rule should clearly outline the requirements for type definitions, including the necessity for all variables, function parameters, and return types to have explicit types defined. Additionally, include examples of both compliant and non-compliant code snippets to illustrate the rule effectively. Ensure the language is clear and concise, suitable for developers to understand and implement easily.
Add TypeScript Linting
Please provide a comprehensive linting configuration for a TypeScript project that enforces strict type safety. Include specific settings that should be applied in the configuration file, such as rules for type checking, unused variables, and any other relevant options that enhance type safety. Additionally, explain the purpose of each setting and how it contributes to maintaining strict type safety in the codebase. Format the response as a JSON object that can be directly used in a TypeScript project.
Implement Code Review Checklist
Create a comprehensive checklist for conducting code reviews with a strong emphasis on type safety in TypeScript. The checklist should include items such as verifying that all variables have explicit types, ensuring that functions have well-defined return types, checking for proper use of TypeScript interfaces and types, and confirming that any type assertions are justified and necessary. Additionally, include guidelines for assessing the use of union and intersection types, as well as best practices for handling any potential type errors. Format the checklist in a clear, organized manner with bullet points for easy reference.
Establish Naming Conventions
Help me establish comprehensive naming conventions for a TypeScript project that promote clarity and type safety. The conventions should cover variable names, function names, class names, and interface names, ensuring that they are descriptive and follow a consistent pattern. Include examples for each type of naming convention and explain the rationale behind each choice. Additionally, provide guidelines on how to handle naming for complex types and generics to maintain readability and prevent confusion.
Set Up Pre-commit Hooks
Help me set up pre-commit hooks that will run TypeScript checks before any commits are made. I want the configuration to include the necessary scripts to ensure that TypeScript code adheres to strict mode and catches any potential errors. Please provide a detailed example of the configuration file, including any specific commands or tools that should be used to enforce these checks. Additionally, explain how to integrate this setup into a Git workflow to ensure it runs automatically on each commit.
Claude Code may default to any types when it encounters ambiguous type definitions. Ensuring clear and explicit type definitions helps prevent this.
Enable strict mode in your tsconfig.json by setting 'strict': true. This ensures all strict type checks are applied.
Using ts-ignore comments can hide underlying type issues, leading to potential runtime errors. It's better to resolve the root cause.
Regularly run TypeScript checks and use linting tools to identify and address type safety violations promptly.
Include guidelines for using specific types, avoiding any types, and resolving type errors without ts-ignore comments.
AI Prompts for Identify Type Safety Violations
By bypassing TypeScript type safety, the AI may introduce runtime errors that are difficult to debug.
See promptsAI Prompts for Enforcing TypeScript Type Safety
Cursor bypassing TypeScript type safety leads to runtime errors and unstable code.
See promptsAI Prompts for Enforcing TypeScript Strict Mode
GitHub Copilot sometimes bypasses TypeScript type safety by suggesting 'any' types, incorrect type assertions, or using 'ts-ignore' comments.
See prompts