-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Check and remove unnecessary @ts-expect-error suppressions #40627
Check and remove unnecessary @ts-expect-error suppressions #40627
Conversation
@Julesssss 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] |
Is this done? Melvin did not auto request a review from me because you made the PR ready for review without adding the issue number in the template. If this is ready please complete the checklist. |
Hello But in any case, the PR is about 50 percent ready) I will write to you when the PR is ready for review ) |
Hello )
|
I think, I'm missing what rule are we talking about 😄
Please link what are the issues 🤔
These have to stay unfortunately |
and sorry about the rule inside patches And problem with libraries
|
src/Expensify.tsx
Outdated
@@ -74,7 +74,7 @@ type ExpensifyOnyxProps = { | |||
|
|||
type ExpensifyProps = ExpensifyOnyxProps; | |||
|
|||
const SplashScreenHiddenContext = React.createContext({}); | |||
const SplashScreenHiddenContext = React.createContext<{isSplashHidden?: boolean}>({}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's extract the type to a separate type
src/libs/ObjectUtils.ts
Outdated
const keys1 = Object.keys(obj1) as Array<keyof typeof obj1>; | ||
const keys2 = Object.keys(obj2) as Array<keyof typeof obj2>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are these assertions necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's improve shallowCompare
:
function shallowCompare(obj1?: Record<string, unknown>, obj2?: Record<string, unknown>): boolean {
if (!obj1 && !obj2) {
return true;
}
if (obj1 && obj2) {
const keys1 = Object.keys(obj1);
const keys2 = Object.keys(obj2);
return keys1.length === keys2.length && keys1.every((key) => obj1[key] === obj2[key]);
}
return false;
}
export default shallowCompare;
And then you have to make the following adjustments:
diff --git a/src/libs/Navigation/AppNavigator/getPartialStateDiff.ts b/src/libs/Navigation/AppNavigator/getPartialStateDiff.ts
index 4c18e161c9..5061c75007 100644
--- a/src/libs/Navigation/AppNavigator/getPartialStateDiff.ts
+++ b/src/libs/Navigation/AppNavigator/getPartialStateDiff.ts
@@ -53,7 +53,7 @@ function getPartialStateDiff(state: State<RootStackParamList>, templateState: St
(stateTopmostCentralPane &&
templateStateTopmostCentralPane &&
stateTopmostCentralPane.name !== templateStateTopmostCentralPane.name &&
- !shallowCompare(stateTopmostCentralPane.params, templateStateTopmostCentralPane.params))
+ !shallowCompare(stateTopmostCentralPane.params as Record<string, unknown> | undefined, templateStateTopmostCentralPane.params as Record<string, unknown> | undefined))
) {
// We need to wrap central pane routes in the central pane navigator.
diff[NAVIGATORS.CENTRAL_PANE_NAVIGATOR] = templateStateTopmostCentralPane;
@@ -73,7 +73,7 @@ function getPartialStateDiff(state: State<RootStackParamList>, templateState: St
(stateTopmostFullScreen &&
templateStateTopmostFullScreen &&
stateTopmostFullScreen.name !== templateStateTopmostFullScreen.name &&
- !shallowCompare(stateTopmostFullScreen.params, templateStateTopmostFullScreen.params))
+ !shallowCompare(stateTopmostFullScreen.params as Record<string, unknown> | undefined, templateStateTopmostFullScreen.params as Record<string, unknown> | undefined))
) {
diff[NAVIGATORS.FULL_SCREEN_NAVIGATOR] = fullScreenDiff;
}
diff --git a/src/libs/Navigation/linkTo.ts b/src/libs/Navigation/linkTo.ts
index 863cb102ad..b21a24a76e 100644
--- a/src/libs/Navigation/linkTo.ts
+++ b/src/libs/Navigation/linkTo.ts
@@ -153,7 +153,7 @@ export default function linkTo(navigation: NavigationContainerRef<RootStackParam
const isTargetNavigatorOnTop = topRouteName === action.payload.name;
const isTargetScreenDifferentThanCurrent = Boolean(topmostCentralPaneRoute && topmostCentralPaneRoute.name !== action.payload.params?.screen);
- const areParamsDifferent = !shallowCompare(topmostCentralPaneRoute?.params, action.payload.params?.params);
+ const areParamsDifferent = !shallowCompare(topmostCentralPaneRoute?.params as Record<string, unknown> | undefined, action.payload.params?.params);
// In case if type is 'FORCED_UP' we replace current screen with the provided. This means the current screen no longer exists in the stack
if (type === CONST.NAVIGATION.TYPE.FORCED_UP) {
@@ -49,7 +49,7 @@ import SendButton from './SendButton'; | |||
type ComposerRef = { | |||
blur: () => void; | |||
focus: (shouldDelay?: boolean) => void; | |||
replaceSelectionWithText: (text: string, shouldAddTrailSpace: boolean) => void; | |||
replaceSelectionWithText: (text: string, shouldAddTrailSpace: Emoji) => void; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about this?
replaceSelectionWithText: (text: string, shouldAddTrailSpace: Emoji) => void; | |
replaceSelectionWithText: OnEmojiSelected; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch )
(text: string | undefined) => { | ||
if (text === undefined) { | ||
return; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to test this change 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed this changes
Because we can pass only string and undefined in this function is not needed
@@ -91,13 +91,12 @@ function StateSelectionPage() { | |||
shouldShowBackButton | |||
onBackButtonPress={() => { | |||
const backTo = params?.backTo ?? ''; | |||
let backToRoute = ''; | |||
let backToRoute = '' as Route; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion:
let backToRoute: Route | undefined;
if (backTo) {
backToRoute = appendParam(backTo, 'state', currentState ?? '');
}
Navigation.goBack(backToRoute);
I think we should fix appendParam
so that it returns a Route
type. This way we can avoid assertion in this file
That's unusual, can you investigate why these // ts-expect-errors are added to JS files in the first place? (you don't need to remove them, but at least let's understand why they exist)
Let's try to fix these library ts expect errors, you can augment types from other libraries like we do in |
@ZhenjaHorbach Let me know once PR is ready for review again 😄 |
No problem ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes look good
Is this complete? If it is, please complete the checklist and bump me. Thanks. |
It's not over yet) |
@fabioh8010 @blazejkustra I'm working on PR App/src/components/MoneyRequestConfirmationList.tsx Lines 1017 to 1035 in 5f50430
|
I can share the current status Don't need to remove
Here we are trying to test non-existent methods
Here we are trying to get non-existent this Haven't figured out how to remove rules
I tried to remove this rule but as a result we need to change many types inside React-navigation library and I'm not sure how much that makes sense
I tried updating GithubUtils types but it didn't help
I tried updating types using d.ts files but it didn't help. More precisely, the types refer to our files with types, but the error does not disappear |
@ZhenjaHorbach I think all these ones are okay to leave in the codebase, in some cases isn't really possible to remove and that's understandable. |
Sounds great) @c3024 |
Please remove |
I merged main |
Reviewer Checklist
Screenshots/VideosAndroid: NativeAndroid: mWeb ChromeiOS: NativeiOS: mWeb SafariMacOS: Chrome / SafariMacOS: Desktop |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like there's more changes in this PR besides @ts-expect-error suppressions
could you explain in the description?
@ZhenjaHorbach could you ping me and @c3024 when you are ready for final review? |
Sorry for delay In other places there are cases when I updated the types in the libs, for example |
And PR is ready In the last commits I reverted changes in IOUTest file and added new changes back So technically I didn't change anything much ) @c3024 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
🚀 Deployed to staging by https://github.com/grgia in version: 1.4.75-0 🚀
|
🚀 Deployed to production by https://github.com/puneetlath in version: 1.4.75-1 🚀
|
Details
Fixed Issues
$ #39130
PROPOSAL: #39130 (comment)
Tests
Nothing to test. All changes are related to TS only
Offline tests
Nothing to test. All changes are related to TS only
QA Steps
Nothing to test. All changes are related to TS only
PR Author Checklist
### Fixed Issues
section aboveTests
sectionOffline steps
sectionQA steps
sectiontoggleReport
and notonIconClick
)myBool && <MyComponent />
.src/languages/*
files and using the translation methodSTYLE.md
) were followedAvatar
, I verified the components usingAvatar
are working as expected)StyleUtils.getBackgroundAndBorderStyle(theme.componentBG)
)Avatar
is modified, I verified thatAvatar
is working as expected in all cases)Design
label and/or tagged@Expensify/design
so the design team can review the changes.ScrollView
component to make it scrollable when more elements are added to the page.main
branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTest
steps.Screenshots/Videos
Android: Native
NA
Android: mWeb Chrome
NA
iOS: Native
NA
iOS: mWeb Safari
NA
MacOS: Chrome / Safari
NA
MacOS: Desktop
NA