Skip to content

Refactor: Implement strict typings and error handling in challenge creation form #220

Description

@MohitBareja16

Problem

The challenges/new/page.tsx component is responsible for generating new public challenges, but it relies on multiple any types throughout its logic:

  1. The problems state array is typed as any[].
  2. The UI dropdown mapping iterates with problems.map((p: any) => ...).
  3. The API submission wrapper catches creation failures with catch (error: any).

This completely disables TypeScript checking across the entire form flow. A schema change to the backend Problem object or an unexpected API error object could lead to silent data corruption or runtime UI crashes that the compiler cannot warn developers about.

Solution

Define a strict Problem interface (_id, title) to properly type the component state and dropdown iteration logic. Refactor the catch (error: any) block to use unknown and implement an error instanceof Error check. This enforces strict type safety from the React component state all the way down to the API error handling layer.

Metadata

Metadata

Assignees

No one assigned

    Labels

    gssoc:approvedApproved for GirlScript Summer of Code

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions