AI Prompts for Enforcing TypeScript Strict Mode

20 of the best prompts for enforcing TypeScript strict mode, step by step across 4 stages. Works with ChatGPT, Claude, and Gemini.

AI Prompts for Enforcing TypeScript Strict Mode

20 of the best prompts for enforcing TypeScript strict mode, step by step across 4 stages. Works with ChatGPT, Claude, and Gemini.

Scroll to explore

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. GitHub Copilot sometimes bypasses TypeScript type safety by suggesting 'any' types, incorrect type assertions, or using 'ts-ignore' comments. This can lead to runtime errors and maintainability issues in TypeScript projects. These prompts help developers ensure Copilot adheres to strict type safety, improving code reliability and robustness. Works with ChatGPT, Claude, and Gemini.

Diagnose the Wall

Identify where GitHub Copilot is bypassing TypeScript strict mode.

Identify Problematic Suggestions

Please review the following code snippet: [PASTE CODE]. Identify any instances where 'any' types are used, incorrect type assertions are present, or 'ts-ignore' comments are included. For each issue you find, provide a brief explanation of why it is problematic and suggest a more appropriate type or solution. Additionally, summarize the potential impact of these issues on the overall code quality and type safety.

Diagnose the Wall

Check TypeScript Config

Please analyze my tsconfig.json file to determine if 'strict' mode is enabled. Here is the content of the file: [PASTE CONTENT]. Additionally, provide a brief explanation of what 'strict' mode entails and the implications of enabling or disabling it for my TypeScript project. If 'strict' mode is not enabled, suggest specific changes I should make to the configuration to enable it and any potential issues I should be aware of when doing so.

Diagnose the Wall

List Ignored Errors

Please analyze the following code: [PASTE CODE] and identify all instances where 'ts-ignore' comments are used. For each instance, provide a detailed explanation of why ignoring these TypeScript errors could be problematic, including potential risks to type safety, maintainability, and overall code quality. Additionally, suggest alternative approaches to handling these errors that would align with TypeScript's strict mode principles.

Diagnose the Wall

Find Incorrect Assertions

Please examine the following TypeScript code: [PASTE CODE]. Identify and highlight any incorrect type assertions present in the code. For each incorrect assertion, provide a brief explanation of why it is incorrect and suggest the appropriate type or correction needed. Format your response in a clear and organized manner, listing each issue separately with its corresponding explanation.

Diagnose the Wall

Detect Any Type Usage

Please analyze the following code snippet for instances where 'any' types are used unnecessarily: [PASTE CODE]. For each occurrence, provide a brief explanation of why the use of 'any' is inappropriate in that context. Additionally, suggest more specific type alternatives that could be used to improve type safety and maintainability. Format your response in a clear, structured manner, detailing each instance and your recommendations.

Diagnose the Wall

Isolate and Fix

Focus on correcting the identified type safety violations.

Replace Any Types

Identify and suggest specific type replacements for the 'any' types found in the following TypeScript code: [PASTE CODE]. For each 'any' type, provide a brief explanation of why the suggested type is appropriate and how it improves type safety. Additionally, ensure that the replacements maintain the functionality of the original code and adhere to TypeScript's strict mode guidelines. Format your response clearly, indicating the original 'any' type and the proposed replacement type side by side.

Isolate and Fix

Correct Type Assertions

Please review the following TypeScript code: [PASTE CODE]. Identify any incorrect type assertions and provide the necessary corrections. Explain the changes made and the reasoning behind each correction, ensuring that the code complies with strict mode requirements. Format the response to clearly show the original assertions alongside the corrected versions for easy comparison.

Isolate and Fix

Remove Ts-Ignore Comments

Please review the following TypeScript code snippet: [PASTE CODE]. Identify any instances where 'ts-ignore' comments are used and suggest modifications to eliminate the need for these comments. Provide a detailed explanation for each change, including how it resolves the underlying type issues and improves type safety. Ensure that the revised code adheres to strict mode requirements and maintains the original functionality.

Isolate and Fix

Enhance Type Definitions

Please propose enhanced type definitions for the following interfaces and types: [PASTE CODE]. Ensure that the definitions are compatible with TypeScript's strict mode. Include detailed comments explaining the purpose of each type and interface, and suggest any necessary modifications to improve type safety and clarity. Additionally, provide examples of how these enhanced definitions can be used in practice to demonstrate their effectiveness.

Isolate and Fix

Refactor for Type Safety

Refactor the following code to ensure it fully complies with TypeScript strict mode: [PASTE CODE]. Please identify any type-related issues, such as implicit any types, and provide explicit type annotations where necessary. Additionally, ensure that all function parameters and return types are properly typed, and that any potential null or undefined values are handled appropriately. Present the refactored code in a clear format, highlighting the changes made for better type safety.

Isolate and Fix

Verify the Resolution

Ensure that the fixes have resolved the type safety issues.

Run TypeScript Compiler

Please compile the following TypeScript code: [PASTE CODE]. Report any type errors you encounter, and provide a detailed explanation of each error, including the line number and a suggestion for how to fix it. Additionally, summarize the overall status of the code, indicating whether it successfully compiles or if there are critical issues that need addressing.

Verify the Resolution

Check for Any Types

Please review the following TypeScript code: [PASTE CODE]. Identify any instances where the 'any' type is used and provide a detailed explanation of why using 'any' is discouraged in strict mode. Additionally, suggest appropriate type replacements for each instance of 'any' to ensure type safety and compliance with TypeScript's strict mode guidelines. Format your response as a list, clearly indicating the line number and the suggested type for each occurrence.

Verify the Resolution

Confirm Type Assertions

Please review the following TypeScript code: [PASTE CODE]. Confirm that all type assertions are correct and provide feedback on any potential issues or improvements. Additionally, explain the reasoning behind your confirmations and suggest best practices for type assertions in TypeScript, including any relevant examples. Aim for a detailed response that covers the implications of incorrect type assertions and how they can affect code quality and maintainability.

Verify the Resolution

Validate Ts-Ignore Removal

Please validate the removal of all 'ts-ignore' comments from the following TypeScript code: [PASTE CODE]. Ensure that the code compiles without any errors after these comments have been removed. Additionally, provide a summary of any issues encountered during the validation process, including specific lines of code that may still cause errors or warnings, and suggest potential fixes for those issues.

Verify the Resolution

Ensure Strict Mode Compliance

Please analyze the following codebase for compliance with TypeScript's strict mode. Identify any violations or areas where the code does not adhere to strict type checking rules. For each violation found, provide a brief explanation of the issue, suggest potential fixes, and indicate the specific lines of code where the violations occur. The code to analyze is: [PASTE CODE]. Format your findings in a clear report that includes a summary of the total number of violations and their types.

Verify the Resolution

Prevent Recurrence

Create safeguards to maintain TypeScript strict mode adherence.

Create a CLAUDE.md Rule

Please draft a new rule for a CLAUDE.md file that enforces TypeScript strict mode for all future code submissions. The rule should clearly state the importance of using strict mode, including benefits such as improved type safety and error detection. Include specific guidelines on how to enable strict mode in TypeScript projects, and outline any consequences for not adhering to this rule. Additionally, provide examples of common issues that strict mode helps to catch, and suggest best practices for maintaining strict compliance in code submissions.

Prevent Recurrence

Add Type Safety Comments

Please add a comment at the top of each file in the project that emphasizes the importance of adhering to TypeScript strict mode. The comment should clearly state the benefits of type safety, such as reducing runtime errors and improving code maintainability. Additionally, include a brief reminder of the specific strict mode options that should be followed, like 'noImplicitAny' and 'strictNullChecks.' Ensure the comment is concise yet informative, ideally no more than four sentences.

Prevent Recurrence

Develop a Session-Opener Checklist

Please create a detailed checklist for developers to use before starting a coding session that ensures adherence to TypeScript strict mode. The checklist should include specific items such as verifying that all variables are explicitly typed, checking for the use of 'any' type, ensuring that all function return types are defined, and confirming that strict null checks are enabled. Additionally, include best practices for maintaining type safety and avoiding common pitfalls. Format the checklist in a clear, easy-to-follow manner with bullet points for each item.

Prevent Recurrence

Establish Naming Conventions

Please define a set of clear naming conventions for types and interfaces in TypeScript that promote clarity and type safety. Include guidelines on how to name types, interfaces, enums, and any other relevant constructs. Explain the rationale behind each convention and provide examples for each case. Additionally, outline any best practices for maintaining consistency across a codebase, such as using prefixes or suffixes, and how these conventions can help prevent common type-related issues.

Prevent Recurrence

Implement a Project Guard

Create a project guard script that will automatically check for TypeScript strict mode violations prior to any code commits. The script should analyze the codebase for compliance with strict mode rules and provide detailed feedback on any violations found. Include functionality to generate a report that outlines the specific issues, their locations in the code, and suggestions for how to resolve them. Additionally, ensure the script can be easily integrated into a pre-commit hook in a Git workflow. Format the output in a clear and organized manner for easy review by developers.

Prevent Recurrence

Frequently asked questions

Why does GitHub Copilot suggest 'any' types?+

GitHub Copilot suggests 'any' types when it lacks sufficient context to infer a more specific type. Providing more context or explicit type definitions can improve its suggestions.

How can I stop Copilot from using 'ts-ignore'?+

Ensure your TypeScript code is error-free and provide clear type definitions. This reduces the likelihood of Copilot suggesting 'ts-ignore' comments.

What should I do if Copilot suggests incorrect type assertions?+

Review the suggested type assertions and provide Copilot with more context or correct examples to improve its future suggestions.

Can I configure Copilot to adhere to TypeScript strict mode?+

While you cannot directly configure Copilot, maintaining a strict tsconfig.json and providing clear type annotations can guide its suggestions.

How does Copilot determine type suggestions?+

Copilot uses the context from open files and recent edits to generate type suggestions. Ensuring your code is well-typed helps Copilot make accurate suggestions.