You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: remove 25 response-type as unknown as casts from API layer (#1090)
Phase 1 of #1068 — eliminates all response-type `as unknown as` casts
from `src/lib/api/` by widening `unwrapResult<T>` and
`unwrapPaginatedResult<T>` to accept `{ data: unknown }` instead of `{
data: T }`. Callers now specify the target type via the generic
parameter rather than casting the return value, centralizing the single
`data as T` cast in `infrastructure.ts`.
**Cast count: 31 → 8** (the remaining 8 are request-body casts,
undocumented-query-param casts, and path-parameter casts for non-numeric
dashboard slugs that require backend spec changes).
Also:
- Removes redundant `result as` casts at `unwrapPaginatedResult` call
sites
- Downgrades `data.event as unknown as SentryEvent` to a single `as
SentryEvent` in `resolveEventInOrg`
## Testing
`tsc --noEmit` passes (only pre-existing errors from missing generated
files). `biome check` passes clean.
Closes#1068
<!--
## Plan
### Problem
30+ `as unknown as` casts in `src/lib/api/` bridge SDK-generated
response types to CLI wrapper types. The runtime shapes match, but the
casts prevent TypeScript from catching regressions.
### Root cause
`unwrapResult<T>` required `{ data: T; error: undefined }` as input,
forcing callers to either:
1. Cast the SDK result to match the local wrapper type before passing it
in
2. Cast the return value after calling unwrapResult
### Fix
Widen the `result` parameter of both `unwrapResult<T>` and
`unwrapPaginatedResult<T>` from `{ data: T; ... }` to `{ data: unknown;
... }`. The functions already cast `data as T` internally, so the
generic `T` now serves purely as the output type — callers specify it at
the call site.
### Files changed
- `infrastructure.ts` — widen `unwrapResult<T>` and
`unwrapPaginatedResult<T>` signatures
- `teams.ts` — 3 response casts removed
- `organizations.ts` — 2 response casts removed
- `events.ts` — 2 response casts removed, 1 downgraded to single `as`
- `releases.ts` — 8 response casts removed, 1 comment removed
- `dashboards.ts` — 3 response casts removed (dashboard_id path-param
casts kept as-is for non-numeric slugs)
- `projects.ts` — 5 response/result casts removed
- `monitors.ts` — 2 casts removed (1 redundant, 1 result-argument)
- `repositories.ts` — 2 casts removed
- `issues.ts` — 1 result-argument cast removed
### Out of scope (Categories 2-3)
- 5 request body casts (need backend OpenAPI spec fixes)
- 1 undocumented `collapse` query param cast (needs spec addition)
- 2 dashboard_id path-param casts (API spec types `number` but accepts
string slugs at runtime)
-->
---------
Co-authored-by: jared-outpost[bot] <jared-outpost[bot]@users.noreply.github.com>
Co-authored-by: jared-outpost[bot] <286517962+jared-outpost[bot]@users.noreply.github.com>
0 commit comments