-
Notifications
You must be signed in to change notification settings - Fork 3k
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
[TS migration] Migrate 'HeaderGap' component to TypeScript #32567
[TS migration] Migrate 'HeaderGap' component to TypeScript #32567
Conversation
import useThemeStyles from '@styles/useThemeStyles'; | ||
import HeaderGapComponent from './types'; | ||
|
||
// eslint-disable-next-line react/function-component-definition, react/prop-types |
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.
@SzymczakJ Let's actually disable react/prop-types
rule globally (.eslintrc.js
) for Typescript files.
src/components/HeaderGap/index.tsx
Outdated
import HeaderGapComponent from './types'; | ||
|
||
// eslint-disable-next-line react/function-component-definition | ||
const HeaderGap: HeaderGapComponent = () => null; | ||
|
||
HeaderGap.displayName = 'HeaderGap'; | ||
export default HeaderGap; |
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.
Maybe we can keep function component definition and keep it this way for example to follow our common rules. Also this was we can get rid of elsint ignore in index.desktop.tsx
file.
@SzymczakJ @blazejkustra what do you think?
import HeaderGapComponent from './types'; | |
// eslint-disable-next-line react/function-component-definition | |
const HeaderGap: HeaderGapComponent = () => null; | |
HeaderGap.displayName = 'HeaderGap'; | |
export default HeaderGap; | |
import type {HeaderGapProps} from './types'; | |
// eslint-disable-next-line @typescript-eslint/no-unused-vars | |
function HeaderGap({styles}: HeaderGapProps) { | |
return null; | |
} | |
HeaderGap.displayName = 'HeaderGap'; | |
export default HeaderGap; | |
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 idea, changed component the way you wanted. What do you think?
import HeaderGapProps from './types'; | ||
|
||
function HeaderGap({styles}: HeaderGapProps) { | ||
const themeStyles = useThemeStyles(); |
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.
const themeStyles = useThemeStyles(); | |
const themeStyles = useThemeStyles(); | |
src/components/HeaderGap/index.tsx
Outdated
import HeaderGapProps from './types'; | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
function HeaderGap({styles}: HeaderGapProps): ReactNode { |
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 usually don't add return type to components
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.
Without it the return type would be null
, that's why it was initially typed like this:
const HeaderGap: HeaderGapComponent = () => null;
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 already have something similar with SplashScreenHider for example.
And the component seems to work as expected.
But if you think it's better to keep your initial typing I'm okay with that!
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.
@VickyStash I think we need to adjust SplashScreenHider return type. Default implementation index.tsx
returns null
, but native implementation index.native.tsx
returns an Element
. The problem is that typescript infers the type from default implementation so whenever you use this component it's treated like it returns null
which isn't entirely true..
And the component seems to work as expected.
It does, but the type is misleading 😅
But if you think it's better to keep your initial typing I'm okay with that!
I think the most clean is to make it an exception and leave the return type for HeaderGap
and SplashScreenHider
, as it is now
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.
@SzymczakJ Let's move the return type to types.ts
and reuse this type in implementations. Go ahead and adjust SplashScreenHider as well, thanks!
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.
Fixed comments! @VickyStash @blazejkustra what do you think?
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
Reviewer Checklist
Screenshots/VideosAndroid: NativeN/A Android: mWeb ChromeN/A iOS: NativeN/A iOS: mWeb SafariN/A MacOS: Chrome / SafariN/A |
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.
Also LGTM, thank you guys! 🚀
✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release. |
🚀 Deployed to staging by https://github.com/marcochavezf in version: 1.4.13-0 🚀
|
🚀 Deployed to staging by https://github.com/marcochavezf in version: 1.4.13-0 🚀
|
🚀 Deployed to production by https://github.com/jasperhuangg in version: 1.4.13-8 🚀
|
Details
Migrate 'HeaderGap' component to TypeScript. During this task i noticed that webpack doesn't include .desktop.tsx files in bundle when running desktop app and desktop app wouldn't work if we wanted to write some desktop specific code, I've put out a PR that fixes this. Without that PR all components that have .desktop.tsx files won't work properly.
I also changed SplashScreenHider so that it's typed better(so it doesn't say it returns null, but ReactNode), because it was a similar case to HeaderGap component(more details in comments below).
Fixed Issues
$ #24990
PROPOSAL: N/A
Tests
Offline tests
QA Steps
Same as tests
PR Author Checklist
### Fixed Issues
section aboveTests
sectionOffline steps
sectionQA steps
sectiontoggleReport
and notonIconClick
)myBool && <MyComponent />
.src/languages/*
files and using the translation methodWaiting for Copy
label for a copy review on the original GH to get the correct copy.STYLE.md
) were followedAvatar
, I verified the components usingAvatar
are working as expected)StyleUtils.getBackgroundAndBorderStyle(themeColors.componentBG)
)Avatar
is modified, I verified thatAvatar
is working as expected in all cases)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
Android: mWeb Chrome
iOS: Native
ios.mov
iOS: mWeb Safari
iosweb.mov
MacOS: Chrome / Safari
web.mov
MacOS: Desktop
desktop.mov