Typical AI response when using prompts/code-quality/typescript.md on a PR with component and API changes.
components/UserCard.tsx
-
Line 12 —
useris implicitlyanybecausegetUser()has no return type. Fix: Definetype User = { id: string; name: string; avatar?: string }and type the return asgetUser(): Promise<User>. -
Line 18 —
onClickprop is untyped in the component's props. Fix: AddonClick?: () => voidto the props interface.
app/api/users/route.ts
-
Line 5 —
searchParamsis used as a generic object;get('q')returnsstring | null. Fix: Narrow withconst q = searchParams.get('q') ?? ''or extract from typedNextRequest. -
Line 22 — Response returns
anybecausefetchUsers()is untyped. Fix: Type the return asfetchUsers(): Promise<User[]>and use it inResponse.json().
lib/auth.ts
- Line 8 —
sessionallowsundefinedbut is used without a guard. Fix: Addif (!session) return nullbefore accessing session properties.
| File | Issues |
|---|---|
UserCard.tsx |
2 (implicit any, untyped props) |
api/users/route.ts |
2 (searchParams, untyped return) |
lib/auth.ts |
1 (nullable session) |
Total: 5. Prioritize typing getUser/fetchUsers and the UserCard props.