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

refactor(javascript): type setTimeout in a way compatible with node & browser #527

Merged
merged 1 commit into from
May 23, 2022

Conversation

Haroenv
Copy link
Contributor

@Haroenv Haroenv commented May 20, 2022

🧭 What and Why

in node the output of setTimeout is NodeJS.Timeout, in browser it's number. This difference doesn't matter for us, and thus the return type can be used.

This allows us (if needed) to run the type checking with both node types enabled and disabled.

Changes included:

  • internally setTimeout types have been changed from NodeJS.Timeout to ReturnType

🧪 Test

TSC works

@Haroenv Haroenv requested review from millotp and shortcuts May 20, 2022 11:25
@netlify
Copy link

netlify bot commented May 20, 2022

Deploy Preview for api-clients-automation ready!

Name Link
🔨 Latest commit a2ca654
🔍 Latest deploy log https://app.netlify.com/sites/api-clients-automation/deploys/62877abe6d38d700088be070
😎 Deploy Preview https://deploy-preview-527--api-clients-automation.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@algolia-bot
Copy link
Collaborator

algolia-bot commented May 20, 2022

✗ The generated branch has been deleted.

If the PR has been merged, you can check the generated code on the main branch.
You can still access the code generated on main via this commit.

@Haroenv Haroenv changed the title refactor(xhr): type setTimeout in a way compatible with node & browser refactor(javascript): type setTimeout in a way compatible with node & browser May 20, 2022
Copy link
Member

@shortcuts shortcuts left a comment

Choose a reason for hiding this comment

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

Nice :D

@@ -54,7 +53,7 @@ export function createXhrRequester(): Requester {
// istanbul ignore next
if (baseRequester.status === 0) {
clearTimeout(connectTimeout);
clearTimeout(responseTimeout as NodeJS.Timeout);
clearTimeout(responseTimeout!);
Copy link
Member

Choose a reason for hiding this comment

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

Maybe a if to avoid having !?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it's not actually needed, clearTimeout accepts null and undefined too, just type types don't allow that

@Haroenv Haroenv requested a review from shortcuts May 20, 2022 15:24
Copy link
Member

@shortcuts shortcuts left a comment

Choose a reason for hiding this comment

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

Nice ty :D

@shortcuts shortcuts merged commit 000f62d into main May 23, 2022
@shortcuts shortcuts deleted the refactor/ts-settimeout branch May 23, 2022 09:14
algolia-bot added a commit to algolia/algoliasearch-client-javascript that referenced this pull request May 23, 2022
@shortcuts shortcuts mentioned this pull request May 23, 2022
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants