refactor: improve grid service type safety (partial Phase 3.2)

- 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 <noreply@anthropic.com>
This commit is contained in:
Justin Edmund 2025-11-28 21:51:44 -08:00
parent 3b2782ec89
commit 53405da7eb

View file

@ -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