-
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 'compose.js' lib to TypeScript #26970
[TS migration] Migrate 'compose.js' lib to TypeScript #26970
Conversation
@hayata-suenaga @fabioh8010 I need your eyes on this PR as it is quite tricky, everything is explained in the PR's description (Fabio is ooo so he'll probably see this in the upcoming week). |
Hi @blazejkustra, could you provide more info about why Redux and flowRight types didn't work? What type of problems are you having? |
let me know if you need input from me @blazejkustra @fabioh8010 🙇 |
type Func<T extends unknown[], R> = (...a: T) => R;
export default function compose(): <R>(a: R) => R;
export default function compose<F extends Function>(f: F): F;
/* two functions */
export default function compose<A, T extends unknown[], R>(f1: (a: A) => R, f2: Func<T, A>): Func<T, R>;
/* three functions */
export default function compose<A, B, T extends unknown[], R>(f1: (b: B) => R, f2: (a: A) => B, f3: Func<T, A>): Func<T, R>;
/* four functions */
export default function compose<A, B, C, T extends unknown[], R>(f1: (c: C) => R, f2: (b: B) => C, f3: (a: A) => B, f4: Func<T, A>): Func<T, R>;
/* rest */
export default function compose<R>(f1: (a: unknown) => R, ...funcs: Function[]): (...args: unknown[]) => R;
export default function compose<R>(...funcs: Function[]): (...args: unknown[]) => R;
export default function compose(...funcs: Function[]): Function {
if (funcs.length === 0) {
// infer the argument type so it is usable in inference down the line
return <T>(arg: T) => arg;
}
if (funcs.length === 1) {
return funcs[0];
}
return funcs.reduce(
(a, b) =>
(...args: any) =>
a(b(...args)),
);
}
const composed = compose(withInjected, withInjected2); // Func<unknown[], unknown>
const y = composed(AvatarWithDisplayName); // unknown @fabioh8010 I can't get it to work at all, I either get errors or unknown as in the snippet above. It's not inferring correctly or I'm missing something 🤷 |
@mananjadhav 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] |
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.
As we discussed previously on Slack, I agree that we have to keep the typing order of the compose function reversed in order to work, while the compose implementation won't change.
LGTM, CK still need to do the checklist.
Reviewer Checklist
Screenshots/VideosWebweb.mp4Mobile Web - Chromemobile-chrome.mp4Mobile Web - Safarimobile-safari.mp4Desktopdesktop.mp4iOSios.mp4Androidandroid.mp4 |
@mananjadhav can you approve the PR so that an internal is assigned? |
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.
Approving as per the Typescript migration guidelines.
We did not find an internal engineer to review this PR, trying to assign a random engineer to #24788 as well as to this PR... Please reach out for help on Slack if no one gets assigned! |
Thanks for notifying @blazejkustra I missed the notification regarding C+ enabled for TS PR. I'll work on the checklist. |
Reviewer Checklist
Screenshots/VideosWebweb-compose-migration.movMobile Web - Chromemweb-chrome-compose-migration.movMobile Web - Safarimweb-safari-compose-migration.movDesktopdesktop-compose-migration.moviOSios-compose-migration.movAndroidandroid-compose-migration.mov |
@stitesExpensify All yours. 🎀 👀 🎀 C+ reviewed. |
✋ 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/stitesExpensify in version: 1.3.77-0 🚀
|
🚀 Deployed to production by https://github.com/mountiny in version: 1.3.77-7 🚀
|
Details
Migration of 'compose.js' to Typescript. This function was copied from Redux codebase (link). However these types didn't work when I tested it, so I adjusted them in this commit according to how
lodash.flow
is typed here.The problem is that
compose
wraps functions from right, meanwhilelodash.flow
works the other way around (f1(f2(f3(...)))
vsf3(f2(f1(...)))
). I tried usinglodash.flowRight
types but it has almost the same type definition asredux.compose
, both doesn't work.Code for testing:
Fixed Issues
$ #24788
PROPOSAL: N/A
Tests
Offline tests
N/A
QA Steps
N/A
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)/** comment above it */
this
properly so there are no scoping issues (i.e. foronClick={this.submit}
the methodthis.submit
should be bound tothis
in the constructor)this
are necessary to be bound (i.e. avoidthis.submit = this.submit.bind(this);
ifthis.submit
is never passed to a component event handler likeonClick
)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
Web
web.mov
Mobile Web - Chrome
a-web.mov
Mobile Web - Safari
i-web.mov
Desktop
desktop.mov
iOS
ios.mov
Android