News for hackers. Stuff that matters.
Re:SetBigTimeout by wging on Friday October 18, 2024 @02:27PM (#41882110)
In nodejs you at least get a warning along with the problematic behavior:

    Welcome to Node.js v22.7.0.
    Type ".help" for more information.
    > setTimeout(() => console.log('reached'), 3.456e9)
    Timeout { <contents elided> }
    > (node:64799) TimeoutOverflowWarning: 3456000000 does not fit into a 32-bit signed integer.
    Timeout duration was set to 1.
    (Use `node --trace-warnings ...` to show where the warning was created)
    reached
I'm surprised to see that setTimeout returns an object - I assume at one point it was an integer identifying the timer, the same way it is on the web. (I think I remember it being so at one point.)
Re:SetBigTimeout by augusto-moura on Friday October 18, 2024 @02:47PM (#41882311)
It returns an object for a long time now, I might say it was always like this actually. Don't know about very old versions
Re:SetBigTimeout by dgoldstein0 on Friday October 18, 2024 @07:04PM (#41884284)
It's return your differs between node and in a browser. If you want to type a variable to hold the return value in typescript and share that across node (eg jest tests where you might include @types/node) and the browser you need ReturnType<typeof setTimeout>, otherwise the code won't typecheck in all cases. Similar with setInterval.