Repository navigation
Remove unsafe type assertions from native receipt validation - #100214
Conversation
Codecov Report✅ Changes either increased or maintained existing code coverage, great job!
|
|
@ikevin127 Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button] |
Reviewer Checklist
Screenshots/VideosScreen.Recording.iPhone.17.Pro.Max.10-01-2026.at.17.17.33.mp4 |
|
|
||
| import type {ReceiptSource} from '@src/types/onyx/Transaction'; | ||
| import type {FileObject} from '@src/types/utils/Attachment'; | ||
|
|
There was a problem hiding this comment.
🟡 The platform pair now has divergent onSuccess signatures, and TypeScript only ever checks the web one.
index.ts (web) onSuccess: (file: File) => void returns Promise<void | File> | undefined
index.native.ts (native) onSuccess: (file: FileObject) => void returns Promise<void>
There is no moduleSuffixes in tsconfig.json or the inherited expo/tsconfig.base, so @libs/fileDownload/validateReceiptFile resolves to index.ts for every caller. The native signature change is invisible to the type system at every call site.
Today there is exactly one caller (ReceiptFileValidator.tsx:118) and it happens to pass the wider callback, so this is safe right now. The failure mode is the next caller:
// typechecks clean against index.ts, crashes on Android and iOS
validateReceiptFile(name, path, type, (file: File) => uploadBlob(file.slice()), onFailure);index.native.ts hands that callback {uri, name, type, source}, which has no slice. TypeScript signs off because it read the web file.
Make both sides agree:
// index.ts
onSuccess: (file: FileObject) => void,checkIfLocalFileIsAccessible (src/libs/actions/IOU/Receipt.ts:381) declares (file: File) => void, and the augmented File is assignable to FileObject, so passing the widened callback through should still typecheck. Worth running npm run typecheck to confirm rather than taking my word for it.
The return types also diverge (Promise<void | File> | undefined vs Promise<void>), but that predates this PR and the caller already handles it with ?? Promise.resolve(). Not worth touching here.
There was a problem hiding this comment.
Thanks for catching this. I changed the validateReceiptFile callback type to FileObject on both web and native, so callers are checked against the type native actually provides. The updated PR passed the TypeScript check.
| @@ -2,6 +2,7 @@ import checkFileExists from '@libs/fileDownload/checkFileExists'; | |||
| import ReceiptStorage from '@libs/ReceiptStorage'; | |||
|
|
|||
There was a problem hiding this comment.
🟡 The branch is 10152 commits behind main.
There was a problem hiding this comment.
I merged main into the PR branch and resolved the conflict in the native receipt validator. The resolution keeps the newer receipt recheck behavior from main alongside the FileObject type fix. GitHub now reports the PR as mergeable.
| // Rebuilding the receipt from disk makes a fresh File without the trace id from capture, so copy it | ||
| // back from the saved draft. This keeps the capture, submit, and enqueue logs tied to one receipt. |
There was a problem hiding this comment.
🟢 src/pages/iou/request/step/confirmation/ReceiptFileValidator.tsx:93-94 - the comment now says File where native produces a FileObject.
// Rebuilding the receipt from disk makes a fresh File without the trace id from capture, so copy itAccurate on web, no longer accurate on native, and this PR is specifically about making that distinction explicit. "a fresh file object" reads correctly on both platforms.
There was a problem hiding this comment.
Fixed the comment in ReceiptFileValidator to say “file object,” which accurately describes the value on both web and native.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
ikevin127
left a comment
There was a problem hiding this comment.
🟢 LGTM - All previous comments were addressed
|
✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release. |
|
🚧 blimpich has triggered a test Expensify/App build. You can view the workflow run here. |
|
🧪🧪 Use the links below to test this adhoc build on Android, iOS, and Web. Happy testing! 🧪🧪
|
|
🚀 Deployed to staging by https://github.com/blimpich in version: 9.5.15-1 🚀
|
|
No help site update is needed. This PR only changes TypeScript types and a code comment in receipt validation, so receipt handling looks and works the same for users. |
|
🚀 Deployed to production by https://github.com/grgia in version: 9.5.15-3 🚀
Bundle Size Analysis (Sentry): |
Explanation of Change
Removes two unsafe type assertions from native receipt validation by using the app’s receipt-file type. Receipt handling remains unchanged.
Changed files (2)
src/libs/fileDownload/validateReceiptFile/index.native.tssrc/pages/iou/request/step/confirmation/ReceiptFileValidator.tsxFixed Issues
$ #94739
PROPOSAL: #94739 (comment)
Tests
For this PR head, upstream TypeScript, ESLint, formatting and eight Jest test jobs passed.
QA Steps
No additional change-specific manual QA is required for this type/comment-only change.
PR Author Checklist
Unchecked testing items remain pending or lack exact-head evidence in the retained record. The type-only change adds no UI, CSS, copy, assets or focused unit test; these conditional rows do not claim execution.
### Fixed Issuessection aboveTestssectionOffline stepssectionQA stepssectionAvatar, I verified the components usingAvatarare working as expected)StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))npm run compress-svg)Avataris modified, I verified thatAvataris working as expected in all cases)Designlabel and/or tagged@Expensify/designso the design team can review the changes.mainbranch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTeststeps.Screenshots/Videos
MacOS: Chrome / Safari
100214-desktop-corrected.mp4