Skip to content

refactor(api): simplify response types from tuple to direct Zod inference #720

@navin-moorthy

Description

@navin-moorthy

Summary

API response types use a non-standard tuple pattern [T, ...T[]] to enforce non-empty arrays at the type level, but Zod already validates this at runtime with .nonempty(). This adds unnecessary type complexity.

Current Pattern

export type CreateCategoryResponse = [
  z.infer<typeof CreateCategoryResponseSchema>[number],
  ...z.infer<typeof CreateCategoryResponseSchema>,
];

Proposed Change

export type CreateCategoryResponse = z.infer<typeof CreateCategoryResponseSchema>;
// Trust Zod .nonempty() validation at runtime

Affected Files

  • src/app/api/category/create-user-category/route.ts
  • src/app/api/category/update-user-category/route.ts
  • src/app/api/tags/add-tag-to-bookmark/route.ts
  • src/app/api/tags/remove-tag-from-bookmark/route.ts

Notes

Breaking Change: API response type changes affect mobile app consumers. Coordinate with mobile team before implementing.

Priority

P3 - Nice to have, low effort (30 min)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions