So I am learning how to use the factory function in javascript/typescript. I created a to-do list project where I had to pass the instance as a parameter to the function. I wanted to ask is it a bad practice to use this approach
eg
const Animal = ()=>{
const legs = (noOfLegs:number)=>{
console.log(noOfLegs)
}
return {
legs
}
}
const lion = Animal();
//not sure how to typeheck the instance passed to the function
const randomFunc = (lion:ReturnType<typeof Animal>)=>{
lion.legs(4)
}
secondly, if there is no issue with the passing instance as a parameter to the function then how type-check the parameter?