Repository navigation
[No QA] Remove unsafe assertions from shared test utilities - #98485
Conversation
|
@ikevin127 Could you please take a look at this when you get a chance? Thanks! |
|
@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
|
| icon: GenericBank, | ||
| iconStyles: [], | ||
| iconSize: 40, | ||
| bankCurrency: CONST.CURRENCY.USD, | ||
| bankCountry: CONST.COUNTRY.US, | ||
| } satisfies PaymentMethod; | ||
|
|
||
| if (overrides.accountData === null) { | ||
| const {accountData, ...validOverrides} = overrides; | ||
| return { | ||
| ...defaults, | ||
| ...validOverrides, | ||
| // @ts-expect-error -- undefined icons intentionally preserve the established fixture shape. | ||
| icon: overrides.icon, |
There was a problem hiding this comment.
🟢 paymentMethods.ts — the GenericBank default is always discarded, and the icon override is duplicated 3×
const defaults = { ..., icon: GenericBank, ... } satisfies PaymentMethod;
...
return {
...defaults, // icon: GenericBank
...overrides,
// @ts-expect-error -- undefined icons intentionally preserve the established fixture shape.
icon: overrides.icon, // final icon = overrides.icon (undefined when not passed)
};
Every return branch ends with icon: overrides.icon, so icon: GenericBank in defaults is never the actual icon, it exists only to make defaults satisfies PaymentMethod compile, then gets overwritten in all three branches.
A future reader (this is a shared util others copy from) will reasonably wonder why an SVG asset is imported and set only to be thrown away. It also means the icon: overrides.icon + @ts-expect-error triplet is repeated in all three branches.
Since the real intent is "icon defaults to undefined and that deliberately violates the type," it reads cleaner to express that once, e.g. compute the shared base (with the single icon @ts-expect-error) and then apply only the null-branch differences on top, rather than importing GenericBank as a satisfy-the-compiler placeholder.
Behavior is correct as-is (default icon stays undefined, matching the old util); this is purely about the shared util being easy to read and copy.
There was a problem hiding this comment.
@ikevin127 Addressed in 1dc7730.
I removed the discarded GenericBank placeholder, expressed the intentional icon: undefined mismatch once in the typed defaults, and removed the three duplicated icon overrides. This preserves the existing fixture behavior and the malformed null branches.
Could you please take another look? Thanks!
|
@KJ21-ENG One comment above ☝️ that should be addressed before approval, tag me once that's addressed. |
ikevin127
left a comment
There was a problem hiding this comment.
🟢 LGTM - Comment addressed
|
🚀 Deployed to staging by https://github.com/blimpich in version: 9.4.54-0 🚀
|
|
🚀 Deployed to production by https://github.com/Beamanator in version: 9.4.54-4 🚀
Bundle Size Analysis (Sentry): |
Explanation of Change
This test-only cleanup removes three
@typescript-eslint/no-unsafe-type-assertionfindings from three shared test utility files. It replaces broad assertions with production-derived types, narrow compiler-checked invalid-fixture boundaries, and directly typed mock objects while preserving existing runtime fixture behavior.The follow-up repair addresses reviewer feedback in
paymentMethods.ts: the real defaulticon: undefinedmismatch is now documented once at its source, while the discardedGenericBankplaceholder and three duplicated icon overrides were removed. Valid icon overrides and the deliberately malformedaccountData: nullandmethodID: nullfixture branches retain their prior runtime values and precedence.Fixed Issues
$ #94739
PROPOSAL: #94739 (comment)
Count change
Current baseline source:
config/eslint/eslint.seatbelt.tsvat baseff34e26e822b678c7cb1f300996dde35fca7532crecords the baseline for@typescript-eslint/no-unsafe-type-assertion.Before:
tests/utils/collections/paymentMethods.ts: 1tests/utils/collections/reportActions.ts: 1tests/utils/createSharedValueMock.ts: 1After:
Net reduction:
@typescript-eslint/no-unsafe-type-assertionfindings across the 3 target files.TSV evidence:
Tests
PaymentUtilsTest.ts,ReportActionsUtilsTest.ts, andSearchAutocompleteUtilsTest.ts.paymentMethods.ts; its unchanged repository diagnostics remain baseline partial coverage, so the exact-head upstream full typecheck remains authoritative.2d57b8ab103f66a299e8ad08a6b9f73dfc4c0d07found 134 issues on each tree, delta 0, with no new finding.97f1ee349f57b74366eaab2aeaf9f86b7c3d3982and signed head1dc773051182be2bbe13457c46526f774d18e4be.Offline tests
N/A — this is a test-only type-safety cleanup; it changes no application runtime or network behavior, and no manual offline test was performed.
QA Steps
N/A — this is a test-only cleanup and the title starts with
[No QA]; no staging or production manual QA was performed.PR Author Checklist
Each checklist item below is checked because it was considered. Platform, staging or production, offline, screenshot or video, high-traffic, console, and product-component testing are N/A for this test-only cleanup; the automated evidence is listed in
### Tests.### Fixed Issuessection aboveTestssectionOffline stepssectionQA stepssectionAvatar, I verified the components usingAvatarare working as expected)StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))npm run compress-svg)Avatar, 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
N/A — no UI or visual behavior changed; no screenshots or videos were produced.
Changed files (3)
tests/utils/collections/paymentMethods.tstests/utils/collections/reportActions.tstests/utils/createSharedValueMock.ts