Repository navigation
[No QA] Reduce unsafe type assertions in SplitDistanceMessage tests - #95938
Conversation
Target rule: @typescript-eslint/no-unsafe-type-assertion Target files: tests/actions/IOUTest/SplitDistanceMessageTest.ts Verification: completed Generated TSV restored: yes
| function isObject(value: unknown): value is Record<PropertyKey, unknown> { | ||
| return value !== null && typeof value === 'object'; | ||
| } | ||
|
|
||
| function hasDefinedProperty(value: unknown, property: PropertyKey) { | ||
| return isObject(value) && property in value && value[property] !== undefined; | ||
| } | ||
|
|
||
| function hasDefinedAmount(value: unknown): value is Partial<Transaction> & Pick<Transaction, 'amount'> { | ||
| return isObject(value) && typeof value.amount === 'number'; | ||
| } |
There was a problem hiding this comment.
These are all fairly generic methods. And they are named that way as well. Would it not make sense to extract them out into some util or helper file, or even their own dedicated files like we did with tests/utils/createMock.ts so that they can be reused?
There was a problem hiding this comment.
Agreed. I’ll extract the generic isObject and defined-property checks into tests/utils/typeGuards.ts, then reuse them from the related test PRs. I’ll keep hasDefinedAmount local because it is specific to the split-distance fixture and is not a general-purpose guard.
Codecov Report✅ All modified and coverable lines are covered by tests. |
|
failing js test 😢 |
|
Thanks for flagging this. The failing Jest test was caused by an existing main branch issue in ExportOnyxStateTest, where companyCardsLoadingState_ was missing from the safe Onyx keys. The latest main includes that fix, and I merged it into this PR. |
Reviewer Checklist
Screenshots/VideosAndroid: HybridAppAndroid: mWeb ChromeiOS: HybridAppiOS: mWeb SafariMacOS: Chrome / Safari |
|
🚀 Deployed to staging by https://github.com/blimpich in version: 9.4.35-1 🚀
|
|
🚀 Deployed to production by https://github.com/jasperhuangg in version: 9.4.35-6 🚀
|
Explanation of Change
This is a test-only TypeScript cleanup for SplitDistanceMessage coverage. It removes the remaining unsafe type assertions tied to @typescript-eslint/no-unsafe-type-assertion while preserving the existing test scenarios and expectations.
What changed:
Why this approach is safe:
Reviewer focus:
Safety checks:
Fixed Issues
$ #94739
PROPOSAL:
$ #94739 by tightening the test helper typing in tests/actions/IOUTest/SplitDistanceMessageTest.ts instead of casting Onyx entries at each assertion site.
Count change
Current baseline source:
Before:
After:
Net reduction:
TSV evidence:
Exact verification commands:
Tests
Run:
Verify the command succeeds and produces the expected evidence.
Run:
Verify the command succeeds and produces the expected evidence.
Run:
Verify the command succeeds and produces the expected evidence.
Run:
Verify the command succeeds and produces the expected evidence.
Verify the target count decreased from 12 to 0, and total warnings decreased from 5295 to 5283.
Offline tests
Not applicable: this cleanup changes only a TypeScript test file and has no network-dependent runtime behavior.
QA Steps
[No QA]
Not applicable: this is a test-only cleanup with no staging UI or production workflow change.
PR Author Checklist
For checklist items that are not applicable to this cleanup, checked means the item was considered and determined not applicable.
### Fixed Issuessection aboveTestssectionOffline testssection — Not applicable to this test-only cleanup.QA stepssection — Not applicable to this test-only cleanup.Avatar, I verified the components usingAvatarare working as expected) — Not applicable to this test-only cleanup.StyleUtils.getBackgroundAndBorderStyle(theme.componentBG)) — Not applicable to this test-only cleanup.npm run compress-svg) — Not applicable to this test-only cleanup.Avataris modified, I verified thatAvataris working as expected in all cases) — Not applicable to this test-only cleanup.Designlabel and/or tagged@Expensify/designso the design team can review the changes. — Not applicable to this test-only cleanup.mainbranch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTeststeps. — Not applicable to this test-only cleanup.Screenshots/Videos
Not applicable: no UI or visual behavior changed.