typescript-any-eliminator

majiayu000's avatarfrom majiayu000

Elimina uso de `any` en TypeScript creando tipos específicos. Usa cuando veas any en código, errores de tipado, o tarea 2.3 del PLAN_MEJORAS.md.

⭐0stars🔀0forks📁View on GitHub🕐Updated Jan 5, 2026

When & Why to Use This Skill

The TypeScript Any Eliminator is a specialized developer tool designed to enhance code maintainability and type safety. It systematically identifies loose 'any' declarations and replaces them with robust, specific type definitions, custom interfaces, or type guards. By enforcing strict typing, it helps developers reduce runtime errors, improve IDE intellisense, and align projects with modern TypeScript best practices.

Use Cases

  • Technical Debt Refactoring: Automatically scanning and upgrading legacy TypeScript files where 'any' was used as a temporary placeholder to meet strict compiler requirements.
  • Database Schema Integration: Mapping auto-generated database types (such as Supabase or Prisma) to frontend components and services to ensure end-to-end type consistency.
  • Complex Type Resolution: Implementing 'unknown' types combined with custom type guards to safely handle dynamic data from external APIs or third-party libraries.
  • Build Error Optimization: Resolving 'implicit any' errors during the CI/CD process by creating specific interfaces for complex objects and callback functions.
nametypescript-any-eliminator
descriptionElimina uso de `any` en TypeScript creando tipos específicos. Usa cuando veas any en código, errores de tipado, o tarea 2.3 del PLAN_MEJORAS.md.
allowed-toolsRead, Write, Edit, Bash

TypeScript Any Eliminator

Skill para eliminar any y fortalecer el tipado estricto.

Archivos Prioritarios en este Proyecto

  • src/services/quotes.ts (líneas 155, 195, 230, 231, 298, 316)
  • src/services/pdfQuoteService.ts (líneas 93, 114, 146, 175, 256-264)
  • src/hooks/useQuoteBuilder.ts (líneas 45, 46, 215, 246, 373, 441, 587, 661)
  • lib/admin-services.ts (líneas 88, 100, 122, 165, 560, 639)
  • middleware.ts (línea 96)

Estrategias de Reemplazo

1. Datos de Supabase → Usar tipos generados

import type { Database } from '@/src/types/database.types'
type Tables = Database['public']['Tables']

type Cotizacion = Tables['cotizaciones']['Row']
type Lead = Tables['leads']['Row']

2. Tipo desconocido → Usar unknown + type guard

// En lugar de: any
function processData(data: unknown) {
  if (isValidData(data)) {
    // TypeScript sabe que data es ValidData aquí
  }
}

function isValidData(data: unknown): data is ValidData {
  return typeof data === 'object' && data !== null && 'id' in data
}

3. Callbacks de terceros → Tipar el callback

// En lugar de: (error: any) => void
(error: Error | null) => void

4. Objetos dinámicos → Record o tipos específicos

// En lugar de: any
Record<string, unknown>
// O mejor, un tipo específico:
interface FormData {
  [key: string]: string | number | boolean
}

Tipos Sugeridos para este Proyecto

// src/types/quotes.ts
export interface ItemWithProduct {
  id: number
  cotizacion_id: number
  producto_id: number
  cantidad: number
  precio_unitario: number
  subtotal: number
  producto: {
    id: number
    nombre: string
    categoria: string
    imagen_url?: string
  }
}

export interface QuoteWithItems {
  id: number
  codigo: string
  estado: 'borrador' | 'enviada' | 'aceptada' | 'rechazada' | 'expirada'
  total: number
  items_cotizacion: ItemWithProduct[]
  lead?: {
    nombre: string
    email: string
    telefono?: string
  }
}

Instrucciones

  1. Buscar todos los any en el archivo
  2. Entender el contexto de cada uso
  3. Crear tipo específico o usar existente
  4. Reemplazar any
  5. Ejecutar npm run lint && npm run build
  6. Repetir para siguiente archivo

Verificación

# Buscar any restantes
grep -r "any" --include="*.ts" --include="*.tsx" src/ lib/ | grep -v node_modules

# Verificar build
npm run build

Regla de Oro

Si REALMENTE necesitas any (raro), documéntalo:

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const value: any = externalLib.unknownMethod() // TODO: tipar cuando lib actualice tipos