Skip to content

[Enhancement] Audit and remove unsafe TypeScript type casts in store slice action calls #680

Description

@RUKAYAT-CODER

Overview

Several Zustand store action callsites use as Type casts to suppress nullable type errors — e.g., setUser(response.data.user as User) where data.user may be undefined when API response validation is absent. With strict: true in tsconfig.json, TypeScript would catch these as errors if not for the casts. Each unsafe cast hides a potential runtime crash or data corruption.

Specifications

Features:

  • Zero as Type casts used to suppress nullable errors in store action callsites
  • All nullable API response fields narrowed with explicit guards before store dispatch
  • exactOptionalPropertyTypes: true added to tsconfig.json

Tasks:

  • Run grep -rn ' as [A-Z][A-Za-z]*[>;,]' src/ to enumerate suspicious casts
  • For each cast: determine if null is actually possible; add explicit guard or fix upstream type
  • Remove unsafe casts; replace with type narrowing (if (!user) return; etc.)
  • Add exactOptionalPropertyTypes: true to tsconfig.json if not present
  • Verify tsc --noEmit passes with zero errors after all changes

Impacted Files:

  • src/store/slices/ (all slice files)
  • tsconfig.json

Acceptance Criteria

  • Zero as Type casts bypass nullable checks in store action calls
  • tsc --noEmit passes with zero type errors after changes
  • exactOptionalPropertyTypes: true in tsconfig.json
  • No new @ts-ignore or @ts-expect-error suppressions introduced

Metadata

Metadata

Assignees

No one assigned

    Labels

    Stellar WaveIssues in the Stellar wave programenhancementNew feature or request

    Type

    No type
    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