From 53405da7eb18366c777ed86fcb9bf84576f84ebe Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Fri, 28 Nov 2025 21:51:44 -0800 Subject: [PATCH] refactor: improve grid service type safety (partial Phase 3.2) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Created GridItemData type (GridWeapon | GridSummon | GridCharacter) - Typed GridOperation.data field with GridItemData instead of any - Typed draggedItem and targetItem parameters with object shapes - Made targetPosition flexible (number | string) for swaps/moves - Added type guard for move operation to ensure type safety Partial implementation of Phase 3.2 - reduced any usages in grid operations. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- src/lib/services/grid.service.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/lib/services/grid.service.ts b/src/lib/services/grid.service.ts index 66181197..5e662e11 100644 --- a/src/lib/services/grid.service.ts +++ b/src/lib/services/grid.service.ts @@ -2,14 +2,16 @@ import type { Party, GridWeapon, GridSummon, GridCharacter } from '$lib/types/ap import { gridAdapter } from '$lib/api/adapters/grid.adapter' import { partyAdapter } from '$lib/api/adapters/party.adapter' +export type GridItemData = GridWeapon | GridSummon | GridCharacter + export interface GridOperation { type: 'add' | 'replace' | 'remove' | 'move' | 'swap' itemId?: string position?: number - targetPosition?: number + targetPosition?: number | string // Can be position number or gridId string for swaps uncapLevel?: number transcendenceLevel?: number - data?: any + data?: GridItemData } export interface GridUpdateResult { @@ -518,9 +520,9 @@ export class GridService { */ normalizeDragIntent( dragType: 'weapon' | 'summon' | 'character', - draggedItem: any, + draggedItem: { id: string; gridId?: string }, targetPosition: number, - targetItem?: any + targetItem?: { id: string; gridId?: string } ): GridOperation { // If dropping on an empty slot if (!targetItem) { @@ -567,7 +569,7 @@ export class GridService { case 'move': const item = updated.find(i => i.id === operation.itemId) - if (item && operation.targetPosition !== undefined) { + if (item && operation.targetPosition !== undefined && typeof operation.targetPosition === 'number') { item.position = operation.targetPosition } break