interface Identified { id: string | number; } export function moveInArray(items: T[], fromIndex: number, toIndex: number): T[] { if (!Array.isArray(items)) return []; if (fromIndex === toIndex || fromIndex < 0 || toIndex < 0 || fromIndex >= items.length || toIndex >= items.length) { return items; } const next = [...items]; const [moved] = next.splice(fromIndex, 1); if (moved === undefined) return next; // in-range by the guard above; satisfies noUncheckedIndexedAccess next.splice(toIndex, 0, moved); return next; } export function reorderPayload(items: ReadonlyArray | null | undefined): Record { return Object.fromEntries((items || []).map((item, index) => [item.id, index])); } export function movedItemId( before: ReadonlyArray | null | undefined, after: ReadonlyArray | null | undefined, ): string | number | null { const moved = (after || []).find((item, index) => item.id !== before?.[index]?.id); return moved?.id || after?.[0]?.id || null; }