Skip to content

Pervasive as any casts in proof submission and API parameter handling #63

Description

@cybermax4200

Why this matters now: useProofSubmit.ts:48,88-89,126-127,165-176 has multiple as any casts to work around TypeScript's type checking on FormData, error augmentation, and pending proof properties. These casts hide potential runtime errors — for example, (err as any).photoCid = photoCid (line 88) attaches an arbitrary property to an Error object, which could collide with future Error properties or be lost during serialization.

Problem / What: The as any casts in useProofSubmit.ts:

  • Line 48: formData.append('photos', { ... } as any) — bypasses FormData type checking.
  • Lines 88-89: (err as any).photoCid = photoCid — mutates Error objects.
  • Lines 126-127, 165-176: (proof as any).lat, (err as any)?.photoCid — unsafe property access on typed objects.

Key Challenges:

  • Define a ProofSubmitError class that extends Error and has photoCid and metadataCid fields.
  • Define a proper FormDataFile type for the photos field (React Native's FormData accepts { uri, type, name }).
  • Add lat, lng, photoCid, metadataCid to the PendingProof type (they're already part of the data, just not typed).
  • Remove all as any casts and let TypeScript verify the shapes.

Acceptance Criteria:

  • No as any casts in useProofSubmit.ts.
  • ProofSubmitError class for error augmentation.
  • PendingProof type includes lat, lng, photoCid, metadataCid.
  • FormData photo append is properly typed.
  • All property accesses are type-checked.

Relevant files/functions:

  • src/hooks/useProofSubmit.ts:48,88-89,119,126-127,165-176
  • src/types/index.ts:64-74 (PendingProof type)

Out of scope: API response type validation (zod/io-ts).

Labels: type-safety, intermediate, types

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions