fix: Improve Type Safety in nfc.ts and Remove Remaining Usage#562
Conversation
Closes Dev-Card#551 Automated contribution following repo conventions.
|
@openclawloulou-ai is attempting to deploy a commit to the Prashantkumar Khatri's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
Thanks for opening this pull request. This PR has been automatically classified based on the files modified. Applied Labels
Primary Review Area
Reviewer@Harxhit has been identified as the primary reviewer for this pull request. If you have any questions regarding the affected area or implementation details, feel free to reach out to the assigned reviewer. Thank you for your contribution! |
CI — Checks FailedBackend — FAIL
Mobile — SKIP
Web — SKIP
Last updated: |
Harxhit
left a comment
There was a problem hiding this comment.
Please address the lint issues.
Harxhit
left a comment
There was a problem hiding this comment.
Checked this out and tested locally. The change does exactly what it says — every as any in nfc.ts is gone and replaced with real types, with no behavior change. npm run typecheck passes clean.
Verified ✅
- All four
anyusages removed:request.server as FastifyInstance,app.authenticate(cast dropped entirely), andrequest.user as JwtPayload. tsc --noEmitpasses with no errors.app.authenticateresolves correctly via the existingdeclare module 'fastify'augmentation insrc/plugins/prisma.ts, so dropping the(app as any)cast is type-safe.- Behavior is preserved — these are compile-time-only casts, so the runtime auth flow and
/payloadhandler logic are byte-for-byte equivalent. - No new lint problems. The errors ESLint reports on this file (import ordering, unused
ein the catch, missing return type) are all pre-existing on the base branch and untouched by this PR.
Suggestions
- [nit] The
request.server as FastifyInstancecast (line 19) is redundant. Fastify already typesrequest.serverasFastifyInstancenatively, soconst server = request.server;works with no cast. Totally optional. - [low] Consider augmenting
@fastify/jwtinstead of a localJwtPayloadinterface. The localinterface JwtPayload { id: string }works, but the rest of the codebase still relies on(request.user as any).id(profiles.ts,team.ts,event.ts,analytics.ts, etc.). Addingdeclare module '@fastify/jwt' { interface FastifyJWT { user: { id: string } } }would typerequest.userglobally and set up the remaining files for the same cleanup. Out of scope here, but worth a follow-up. - [nit] No test coverage for
nfc.ts. There's nonfc.test.ts, so the auth-fallback chain and/payloadhandler are untested. Not a blocker for a type-only change, but a small regression test would be a nice addition while the file is being touched.
Nothing here blocks merge — the core change is correct and safe. 👍
Reviewed locally — gh pr checkout 562, ran tsc --noEmit (clean), eslint src/routes/nfc.ts (only pre-existing findings), and diffed against base to confirm behavior is preserved. No nfc test files present to run.
Summary
Closes #551
What this PR does
Replace all
as anycasts inapps/backend/src/routes/nfc.tswith specific types imported from your shared Fastify/JWT definitions, such asFastifyInstance,FastifyRequest, and your customUserinterface. Specifically, type theservervariable using the correct Fastify instance type, accessauthenticatevia the properly typedappinstance without casting, and assertrequest.useras your defined user type to safely access theidproperty. Ensure these changes align with existing type declarations to eliminate allanyusages while maintaining TypeScript compliance.Validation
npm --prefix apps/backend run testlocally -- passedAutomated contribution by OpenClaw.