-
-
Notifications
You must be signed in to change notification settings - Fork 365
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
prefer-global-this
should allow window.setTimeout()
and setInterval()
#2482
Comments
…tores/routeUpdating.ts` * allow using `<script lang="tsx">` in rule `vue/block-lang` for `<WidgetSelectForum>` @ eslint.config.js $ yarn eslint --fix @ fe
I disagree. The correct way to handle it is: const id: ReturnType<typeof setTimeout> = window.setTimeout(console.log, 100); |
I had this exact issue yesterday 😅 I wish there was a way to instruct the user on how to proceed in cases like this. Should this specific scenario be handled differently? For example:
I also had issues regarding |
prefer-global-this
: should allow window.setTimeout()
and setInterval()
prefer-global-this
should allow window.setTimeout()
and setInterval()
In my scenario I'm storing the let id = import.meta.client ? 0 : import.meta.server ? new NodeJS.Timeout() : ...; for let id: ReturnType<typeof setTimeout> | undefined = undefined; but this will also violates the eslint rule |
You don't need any of that. Just call setTimeout normally. As for the let, the lint rule is right. This is correct: let id: ReturnType<typeof setTimeout> | undefined;
// and then
id = setTimeout()
clearTimeout(id) |
that requires |
That rules isn't enabled in any recommended config: https://eslint.org/docs/latest/rules/init-declarations As you said, it's completely at odds with |
That was a typo, drop |
|
It doesn't matter as long as you don't use any specific features from node's. In short, use the |
Honestly, I agree with adding this special case to the rule, as it's so classical and common that both versions will be used in a project. |
That's completely irrelevant. This is a type-only issue, I'm closing this for now because the discussion is going nowhere. This is a documentation issue/misunderstanding. I'll open a dedicated issue to improve the DX as described earlier |
Indeed, I ran in to @n0099 Yes I do understand Web API and Node.js API and that's exactly why I'm here. I still think using |
I know that both |
Description
as it's a common workaround: 1, 2, for
globalThis.setTimeout()
andsetInterval()
returningNodeJS.Timeout
in@types/node
Fail
Pass
Additional Info
No response
The text was updated successfully, but these errors were encountered: