looking for some solutions? You are welcome.

SOLVED: how to check a function's type in typescript?

type AssertFuncSync = (...args: any[]) => boolean
type AssertFunc = (...args: any[]) => Promise<boolean>

I have defined two types in typescript above.

Now, in the function demoFunc, I need to check whether the parameter is an AssertFuncSync or an AssertFunc. How can I achieve it?

const demoFunc = (test_func: AssertFunc | AssertFuncSync): any => {
    if (test_func is an AssertFunc) {
        console.log("it belongs to AssertFunc")
        console.log("it belongs to AssertFuncSync")

Posted in S.E.F
via StackOverflow & StackExchange Atomic Web Robots

No comments: