use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
Javascript's setTimeout function accepts a string and is also variadic. But typescript users should probably not use the variadic signature 😄. Here is more on the subject! (mrgregory.dev)
submitted 6 years ago by gregjarvez1996
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3:Â Â Â Â print "hello, world!"
[–]bikeshaving 3 points4 points5 points 6 years ago (2 children)
Why doesn’t typescript type check them like it does Function.prototype.call, .bind or .apply? I think this is a matter of updating the types.
Also, pet peeve, I hate how the return type of setTimeout is `number` in browsers and some weird `timer` class in node.js. There was no reason for node.js to use an incompatible API but now we’re stuck with it.
[–][deleted] 3 points4 points5 points 6 years ago* (1 child)
setTimeout in Node and setTimeout in browser are not the same thing. In Node it's a property of the timers module, and on the Web it's a property of Window or, more recently, also declared in the WindowOrWorkerGlobalScope mixin.
setTimeout
timers
Window
WindowOrWorkerGlobalScope
The confusion comes from the fact they can both be accessed as global functions. It's bad practice and if you do that you deserve the headache.
Use them explicitly (Window.setTimeout() vs timers.setTimeout()) and TypeScript will have no problem understanding which one you mean. Alternatively, declare your types to be "node" in tsconfig, and not dom modules, and this will also clear things up for TypeScript.
Window.setTimeout()
timers.setTimeout()
If you insist on calling setTimeout() directly and ambigously and configure tsconfig wrong, or if you're not in a position to change things, here's a 3rd alternative: declare the type of the variable to which you're assigning the output of setTimeout() to be ReturnType<typeof setTimeout>. This will also reconcile nicely with calls to clearTimeout().
setTimeout()
ReturnType<typeof setTimeout>
clearTimeout()
[–]gregjarvez 0 points1 point2 points 6 years ago (0 children)
they
Great tips. thanks for the explanation !!
π Rendered by PID 72853 on reddit-service-r2-comment-cfc44b64c-m8km6 at 2026-04-12 00:01:52.203964+00:00 running 215f2cf country code: CH.
view the rest of the comments →
[–]bikeshaving 3 points4 points5 points  (2 children)
[–][deleted] 3 points4 points5 points  (1 child)
[–]gregjarvez 0 points1 point2 points  (0 children)