fix: eliminate unsafe any casts in useAuth, socket, axios, and App (#804 #805 #806 #807) - #889
Merged
RUKAYAT-CODER merged 4 commits intoJul 27, 2026
Conversation
|
@Tyler7x Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
Contributor
|
Thank you for contributing to the project. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #804
Closes #805
Closes #806
Closes #807
Summary
Four TypeScript correctness fixes removing
anyassertions and unsafe casts that hid real type errors.#804 — null-safe authErrorCode in useAuth.tsx
getAuthErrorMessage()was called withauthErrorCodewhich could beundefined(when the server error response doesn't include anerrorfield). This produced a broken or misleading error message. Added a conditional: ifauthErrorCodeis falsy, a safe generic fallback ('Authentication failed. Please try again.') is thrown instead.#805 — Typed socket event callbacks
SocketService.on()and the internalregisterLoggedHandler()previously typed their callback parameters asany, meaning event consumers had no type inference for handler data. Changed both toon<T = unknown>(event, callback: (data: T) => void)so callers can pass an explicit generic (e.g.socketService.on<CourseUpdatedPayload>('course_updated', handler)) and get full type safety on the received data.#806 — Runtime validation of 409 ConflictData response
axios.config.tscasterror.response.datato aConflictData-compatible shape purely at the TypeScript level. If the server changes its 409 response format, the cast silently yieldsundefinedfield accesses. AddedisConflictResponseShape()— a lightweight runtime type guard — that validates the object shape before any field access, and reports malformed responses to Sentry instead of propagating corrupt data to the conflict store.#807 — FeatureType guard replaces feature as any in App.tsx
Object.entries(capabilities)returns string keys, butsetFeatureStatusexpects aFeatureTypeenum value. Thefeature as anybypass suppressed this mismatch. Replaced with anisFeatureType(key)predicate that validates membership inObject.values(FeatureType)at runtime, so only valid enum values reachsetFeatureStatusand the cast is provably correct.Files changed
src/hooks/useAuth.tsx— null-safe authErrorCode fallback ([TypeScript] useAuth.tsx accesses authErrorCode without null-check before getAuthErrorMessage() #804)src/services/socket/index.ts— generic typed event callbacks ([TypeScript] socket/index.ts event callbacks typed as any — breaks type inference for handlers #805)src/services/api/axios.config.ts— runtime ConflictData shape guard ([TypeScript] axios.config.ts casts error.response.data to ConflictData without runtime validation #806)App.tsx— isFeatureType guard replaces feature as any ([TypeScript] App.tsx uses feature as any type assertion — hides type errors in degradation store #807)