-1
let delay = false
...
delay && clearTimeout(delay)
        delay = setTimeout(() => {
            callfunc(string, signal)
        }, 2000)

I got delay var and I want it to be either bolean, function and timeout function. What type should it be?

ZygD
  • 22,092
  • 39
  • 79
  • 102
angry kiwi
  • 10,730
  • 26
  • 115
  • 161
  • Please consider modifying the code in this question so as to constitute a [mcve] which, when dropped into a standalone IDE like [The TypeScript Playground](https://tsplay.dev/m3zd2N), clearly demonstrates the issue you are facing (with no typos or undeclared values or types). This will allow those who want to help you to immediately get to work on the issue without first needing to re-create it. And it will make it so that any answer you get is testable against a well-defined use case. – jcalz Sep 05 '21 at 19:50
  • Why do you want it to be so many things? – vaira Sep 05 '21 at 20:54

1 Answers1

1

// set time out always returns a unique id, which will always be a number.

 let timeoutId: Number; // renamed
    timeoutId && clearTimeout(timeoutId)
            timeoutId= setTimeout(() => {
                callfunc(string, signal)
            }, 2000)

Read more here: what does settimeout return

vaira
  • 2,191
  • 1
  • 10
  • 15
  • it's not, here's the error `Type 'Timeout' is not assignable to type 'number'. TS2322` – angry kiwi Sep 06 '21 at 11:53
  • https://stackoverflow.com/questions/55550096/ts2322-type-timeout-is-not-assignable-to-type-number-when-running-unit-te – vaira Sep 06 '21 at 12:13