[TS migration] Migrate 'HeaderGap' component to TypeScript#32567
[TS migration] Migrate 'HeaderGap' component to TypeScript#32567marcochavezf merged 7 commits intoExpensify:mainfrom
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.
@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.
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.
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.
| 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.
We usually don't add return type to components
There was a problem hiding this comment.
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.
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.
@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.
@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.
Fixed comments! @VickyStash @blazejkustra what do you think?
Reviewer Checklist
Screenshots/VideosAndroid: NativeN/A Android: mWeb ChromeN/A iOS: NativeN/A iOS: mWeb SafariN/A MacOS: Chrome / SafariN/A |
marcochavezf
left a comment
There was a problem hiding this comment.
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 Issuessection aboveTestssectionOffline stepssectionQA stepssectiontoggleReportand notonIconClick)myBool && <MyComponent />.src/languages/*files and using the translation methodWaiting for Copylabel for a copy review on the original GH to get the correct copy.STYLE.md) were followedAvatar, I verified the components usingAvatarare working as expected)StyleUtils.getBackgroundAndBorderStyle(themeColors.componentBG))Avataris modified, I verified thatAvataris working as expected in all cases)ScrollViewcomponent to make it scrollable when more elements are added to the page.mainbranch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTeststeps.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