How to check if an object contains a function in TypeScript

1 Answer

0 votes
const obj = {
  mul: (a : number, b : number) => {
    return a * b;
  },
};
 
console.log(typeof obj.mul);
 
console.log(typeof obj.mul === 'function' ? "contains a function" : "not contains a function");
 
 
 
 
/*
run:
  
"function"
"contains a function"
   
*/
   

 



answered Jun 2, 2022 by avibootz
...