QuizNot attempted
A ref that stores a timer id
1–4 to choose, Enter to submit
Show answer & explanation
Correct answer:
useRef<ReturnType<typeof setInterval> | null>(null)
- With
@types/nodeloaded, the globalsetIntervalreturnsNodeJS.Timeoutrather thannumber, soReturnType<typeof setInterval>stays correct whichever typings win (callingwindow.setIntervalexplicitly also givesnumber). - The ref is mutable data, not a DOM node, so assigning to
currentis the whole point. - Not number | null: fails as soon as Node's typings shadow the DOM ones.
- Not HTMLElement | null: a timer id is not a DOM node.
- Not null: the ref could then only ever hold
null.