// Why this is not working
function runAfter1s(fn: () => number){
setTimeout(fn, 1000)
}
const doSomething: () => void = () => {
console.log('Hello')
return 5;
}
runAfter1s(doSomething)
Why this is working
function runAfter1s(fn: () => void){
setTimeout(fn, 1000)
> }
const doSomething: () => void = () => {
console.log('Hello')
return 5;
> }
runAfter1s(doSomething)
I think second one should throw error because we are returning a number while doSomething is defined as void and in first while I have specified dooSomething as void is returning error
New contributor
Yash Jain is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.