Repository navigation
[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] |
fabioh8010
left a comment
There was a problem hiding this comment.
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? |
mananjadhav
left a comment
There was a problem hiding this comment.
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.flowis typed here.The problem is that
composewraps functions from right, meanwhilelodash.flowworks the other way around (f1(f2(f3(...)))vsf3(f2(f1(...)))). I tried usinglodash.flowRighttypes 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 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)/** comment above it */thisproperly so there are no scoping issues (i.e. foronClick={this.submit}the methodthis.submitshould be bound tothisin the constructor)thisare necessary to be bound (i.e. avoidthis.submit = this.submit.bind(this);ifthis.submitis never passed to a component event handler likeonClick)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
Web
web.mov
Mobile Web - Chrome
a-web.mov
Mobile Web - Safari
i-web.mov
Desktop
desktop.mov
iOS
ios.mov
Android