Skip to content
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 'Setup' files to TypeScript #35473

Merged
merged 19 commits into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/libs/checkForUpdates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ function checkForUpdates(platformSpecificUpdater: PlatformSpecificUpdater) {
}, UPDATE_INTERVAL);
}

module.exports = checkForUpdates;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This caused a regression #36522. After changing the export syntax from CommonJS to ESM we had to check the files that depend on that module and update them accordingly.

export default checkForUpdates;
File renamed without changes.
1 change: 1 addition & 0 deletions src/setup/platformSetup/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default () => {};
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,25 @@ function webUpdate() {

if (!Visibility.isVisible()) {
// Page is hidden, refresh immediately
window.location.reload(true);
window.location.reload();
return;
}

// Prompt user to refresh the page
if (window.confirm('Refresh the page to get the latest updates!')) {
window.location.reload(true);
window.location.reload();
}
});
}

type WebUpdater = () => {
init: () => void;
update: () => void;
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a blocker but could we not reuse PlatformSpecificUpdater insted here, somehow?

type PlatformSpecificUpdater = {
update: () => void;
init?: () => void;
};

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can create a types.ts file in @src/setup/platformSetup and then add type PlatformSpecificUpdater to it and use it in both checkForUpdates and index.website.ts by importing it.

Should i do that?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like it would be a little cleaner that way, in that we wouldn't have this duplicate type definition. But in a way, it also feels a little over-complicated for just this simple type...

In the end I don't have a strong opinion, @parasharrajat I'm curious what you'd recommend here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we will be fine with types.ts file. There is no runtime differences.

Copy link
Contributor Author

@HezekielT HezekielT Feb 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I have moved PlatformSpecificUpdater to types.ts and pushed those changes. @francoisl please review again when you get the chance 🙏 . Thanks! cc @parasharrajat

/**
* Create an object whose shape reflects the callbacks used in checkForUpdates.
*
* @returns {Object}
*/
const webUpdater = () => ({
const webUpdater: WebUpdater = () => ({
init: () => {
// We want to check for updates and refresh the page if necessary when the app is backgrounded.
// That way, it will auto-update silently when they minimize the page,
Expand Down
3 changes: 3 additions & 0 deletions src/types/onyx/Session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ type Session = {
/** Currently logged in user encrypted authToken */
encryptedAuthToken?: string;

/** Boolean that indicates whether it is loading or not */
loading?: boolean;

/** Currently logged in user accountID */
accountID?: number;

Expand Down
Loading