Skip to content

fix(audit): accept string | string[] in targetIdFromRequest - #1

Merged
arrrrny merged 1 commit into
mainfrom
fix/audit-target-id-type-mismatch
Jul 30, 2026
Merged

fix(audit): accept string | string[] in targetIdFromRequest#1
arrrrny merged 1 commit into
mainfrom
fix/audit-target-id-type-mismatch

Conversation

@arrrrny

@arrrrny arrrrny commented Jul 30, 2026

Copy link
Copy Markdown
Owner

Problem

AdminSandboxController.recoverSandbox (and ~20 other controller methods across the codebase) had a TypeScript error:

TS2322: Type 'string | string[]' is not assignable to type 'string'.
  Type 'string[]' is not assignable to type 'string'.

This occurred at every @Audit({ targetIdFromRequest: (req) => req.params.* }) call site.

Root Cause

Express's Request.params values are typed as string | string[], but AuditContext.targetIdFromRequest only accepted string | null | undefined. This mismatch caused type errors everywhere the audit decorator accessed route params.

Fix

2 files changed, 2 lines each:

  1. audit/decorators/audit.decorator.ts — Widened AuditContext.targetIdFromRequest return type to string | string[] | null | undefined
  2. audit/interceptors/audit.interceptor.ts — In resolveTargetId, coerce the value: Array.isArray(targetId) ? targetId[0] : targetId

This fixes all affected controllers at once rather than patching each call site individually.

Validation

  • TypeScript diagnostics confirmed clean for sandbox.controller.ts (admin + non-admin) and all other previously-affected controllers
  • nx build api shows 0 errors related to the audit decorator (remaining errors in metrics.interceptor.ts are pre-existing and unrelated)

Express's Request.params values are typed as string | string[], which
caused TS2345 errors in ~20 controller call sites (including
AdminSandboxController) that pass req.params.* to the @Audit decorator.

Root-cause fix: widen AuditContext.targetIdFromRequest return type to
accept string[], and coerce the value in AuditInterceptor.resolveTargetId
by taking the first element when an array is returned.
@arrrrny
arrrrny merged commit 314972e into main Jul 30, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant