Back to ⚡ Performance & Optimization

Debug TypeScript 'any' Proliferation

TypeScriptCode QualityTypesDebugging
---
description: Find and eliminate implicit 'any' types for better type safety
---

1. **Enable Strict Mode**:
- Update tsconfig.json to catch implicit any.
{
"compilerOptions": {
"strict": true,
"noImplicitAny": true,
"strictNullChecks": true
}
}


2. **Find All 'any' Usages**:
- Use ESLint rule.
// .eslintrc.json
{
"rules": {
"@typescript-eslint/no-explicit-any": "error"
}
}


3. **Common Fixes**:
- **Event Handlers**:
// ❌ Bad
const handleClick = (e: any) => {};
// ✅ Good
const handleClick = (e: React.MouseEvent<HTMLButtonElement>) => {};

- **API Responses**:
// ❌ Bad
const data: any = await fetch('/api/user').then(r => r.json());
// ✅ Good
interface User { id: string; name: string; }
const data: User = await fetch('/api/user').then(r => r.json());

- **Third-Party Libraries**:
// ❌ Bad
import someLib from 'some-lib'; // Module has no types
// ✅ Good
npm install --save-dev @types/some-lib


4. **Use 'unknown' Instead of 'any'**:
- Forces type checking before use.
function handleData(data: unknown) {
if (typeof data === 'string') {
console.log(data.toUpperCase()); // ✅ Type-safe
}
}


5. **Generate Types for External APIs**:
- See "Generate TypeScript Types from API" workflow.

6. **Pro Tips**:
- Enable noUncheckedIndexedAccess to catch array/object access bugs.
- Use type assertions sparingly: as Type.
- Prefer type inference over explicit types when obvious.
By Antigravity Team

How to Use This Workflow

Option A: Project-Specific (Recommended)

  1. Click "Download" above
  2. In your project, create the directory: .agent/workflows/
  3. Save the file as debug-typescript-implicit-any-type-safety.md
  4. In Antigravity, type /debug_typescript_implicit_any_type_safety or just describe what you want to do

Learn more about workflows →

Related Workflows

Recommended Rules

View more rules →

Recommended MCP Servers

View more MCP servers →

Take It Further

Maximize your productivity with these powerful resources

📋

Define Your Standards

Set up coding standards to ensure this workflow produces consistent, high-quality results.

Browse Rules Library
📖

Master Workflows

Learn how to create custom workflows, use Turbo Mode, and build your automation library.

Complete Guide