Skip to content

refactor(sync-engine): replace unsafe any type with generic parameter in SyncJob payload #36

Description

@rohansaini-02

Problem

In poc-sync-engine/src/SyncQueue.ts, the payload property of SyncJob is typed as any:

export interface SyncJob {
  id: string;
  url: string;
  method: 'POST' | 'PUT' | 'PATCH' | 'DELETE';
  payload: any;
  timestamp: number;
  retryCount: number;
}

Using any here removes compile-time safety for queued payloads and makes queue consumers harder to type correctly.

Proposed Solution

Refactor SyncJob and SyncQueue to support a generic type parameter, allowing consumers to strongly type queued mutation payloads:

export interface SyncJob<T = unknown> {
  id: string;
  url: string;
  method: 'POST' | 'PUT' | 'PATCH' | 'DELETE';
  payload: T;
  timestamp: number;
  retryCount: number;
}

export class SyncQueue<T = unknown> {
  private queue: SyncJob<T>[] = [];
  
}

A default generic such as unknown can preserve safety while still allowing consumers to specify stricter payload types where needed.

Queue mutation and retrieval methods (e.g. enqueue, dequeue, peek) should preserve the parameterized payload type throughout the API surface.

Acceptance Criteria

  • Raw any type is removed from the SyncJob payload property.
  • TypeScript compiler verifies all queue mutations and reads conform to the parameterized interface.
  • Existing unit tests compile and run successfully.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions