-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
timeoutId does not implement unref() method #6735
Comments
I believe this is related with the fact that setTimeout implementation in node is not the same as in web, that in the latter you will get a number back. So for this kind of cases it will be nice to be able to specify the environment in flowconfig, so this way flow would be able to expose the correspondent libs that apply for it, that is what eslint does to resolve the same issue (see here). In any case, and going back to this specific issue, we should be getting back a number, and this is not the case either, I had a look to the source and I found that's exposed as an opaque type (see here), can you confirm this is also happening for you @gajus? |
That is correct. In DOM, you are going to get back a number. In Node.js, it is an object.
This would make sense. Though, how would two projects with different environments interact with each other?
Referring to what? |
hm, I haven't taken into account this possibility, but I believe it could potentially be handled by adding support for nested configs.
That TimeoutID should be a number and it's not, but after asking you this I realized the reason why we are not getting number is because it's declared as an opaque type. |
The opaque type makes sense because of the mentioned cross-platform compatibility problem, since it hides the implementation details. I think if you have node.js only code and want to use the timeout object's functions you could (should, IMO) define your own TimeoutId type and use that instead of the one from the Flow lib. After all, your code is incompatible with other JS runtimes. Use the Flow lib (opaque) type when you don't use platform specific extensions but only "standard Javascript" timer functions. |
I think it would be nice if Flow exported a stdlib for different environments. Could be a community project too, e.g. import {clearTimeout, setTimeout} from 'flow-stdlib/node'; Only for cases where Node.js/ browser have non-standard features, such as this. |
@gajus This just seems strange, ideally |
Or just this PR #7732 |
The benefit of this approach is that it would make it a clear distinction which dependencies are designed to work in Node.js and which are designed to work in browser. I dig the simplicity of your PR too, though. |
https://flow.org/try/#0PQKgBAAgZgNg9gdzCYAoVBjOA7AzgFzCjjgC4wAVASwFsBTOAV3wEkARMAXjFzv2vpN8ACmEBKLgD4wAbwC+AGjABmAAyqxAbnTE4AOkbYATnSjjNQA
Refer to:
The text was updated successfully, but these errors were encountered: