[priority: critical] 13+ files use as any type casts bypassing TypeScript's type safety
#98
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Severity: Critical — type casts hide real type errors, make data flow untraceable, and defeat the purpose of using TypeScript.
Findings:
gameHooks.tshas 7as anycasts (highest in codebase)page.tsxhas 6craftingStore.tshas 2crafting-design.tshas 6 explicit: anytype annotationseffects.tsusesas unknown as GameStatedouble cast — accepts partial state (4 fields) but passes to function expecting fullGameState(71 fields): anytype annotationsAffected files:
src/app/page.tsx,src/app/components/LeftPanel.tsxsrc/components/game/crafting/EnchantmentDesigner.tsxsrc/components/game/tabs/SpireCombatPage/RoomDisplay.tsx,src/components/game/tabs/SpireCombatPage/SpireCombatPage.tsxsrc/lib/game/crafting-design.ts,src/lib/game/crafting-apply.ts,src/lib/game/effects.tssrc/lib/game/stores/gameHooks.ts,src/lib/game/stores/craftingStore.ts,src/lib/game/stores/combat-actions.tssrc/lib/game/stores/gameActions.ts,src/lib/game/stores/gameLoopActions.ts,src/lib/game/stores/gameStore.tssrc/lib/game/effects/discipline-effects.ts,src/lib/game/effects/upgrade-effects.tssrc/lib/game/hooks/useGameDerived.ts,src/lib/game/utils/discipline-math.tsSuggested fix: Systematically replace
as anywith proper types. For store state access, define proper interfaces. For cross-module boundaries, create shared type definitions. RefactorcomputeAllEffectsto accept only the fields it actually needs.Confidence: High
Dimension: type_safety (score: 58.0%) / logic_clarity
Starting work on eliminating
as anytype casts. Will systematically find and replace with proper types across all affected files.✅ Fixed. Eliminated
as anyand explicit: anytype casts across 18 source files.Changes made:
effects/discipline-effects.ts— ChangedcomputeDisciplineEffects()signature to accept optionalDisciplineStoreStateinstead ofGameState(the parameter was unused internally)effects.ts— RemovedGameStatedependency fromcomputeAllEffects()andgetUnifiedEffects(), fixed import path forComputedEffectsstores/gameHooks.ts— Removed all 7as anycasts by using properUnifiedEffectstype and callingcomputeDisciplineEffects()without argsapp/page.tsx— Removed 6as anycasts, usedUnifiedEffectstype, fixed grimoire spell rendering to use correctSpellDefproperties (eleminstead ofelement,dmginstead ofpower,effectsinstead ofeffect)crafting-design.ts— Replaced 6 explicit: anyannotations withComputedEffects,DesignProgress | null,EquipmentInstancecrafting-apply.ts— ReplacedcomputedEffects: anywithComputedEffectscrafting-actions/design-actions.ts— Replacedlet updates: anywithPartial<GameState>stores/combat-actions.ts,gameActions.ts,gameLoopActions.ts,gameStore.ts— Removedas anyfromcomputeDisciplineEffects()callsstores/craftingStore.ts— Replacedslot as anywithslot as EquipmentSlotapp/components/LeftPanel.tsx— Removedas anyfromupgradeEffects.meditationEfficiencycomponents/crafting/EnchantmentDesigner.tsx— ReplacedallowedEquipmentCategories: any[]withEquipmentCategory[]components/tabs/SpireCombatPage/RoomDisplay.tsx— Removedas anyfromroomTypeandfloorStatecastscomponents/tabs/SpireCombatPage/SpireCombatPage.tsx— Removed 3as anycastscomponents/tabs/StatsTab/CombatStatsSection.tsx— ReplacedactiveSpellDef: anywithSpellDef | nullcomponents/tabs/StatsTab/ManaStatsSection.tsx— Created properManaStatsEffectsinterface extendingComputedEffectscomponents/tabs/StatsTab/ElementStatsSection.tsx— Replaced: anywithElementStatetypecomponents/tabs/StatsTab/LoopStatsSection.tsx— Replaced: anywithSpellStatetypeutils/activity-log.ts— ReplacedeventType as anywitheventType as ActivityEventTypeRemaining: 1
as anyincraftingStore.ts(line 212) — pre-existing architectural mismatch betweenCraftingStoreandGameStatetypes that was previously masked. Fixing properly would require refactoring the entire crafting action layer.Verification: 638/639 tests pass (1 pre-existing failure in
spire-utils.test.ts). All modified files under 400-line limit.