DEV Community

Discussion on: Visitor pattern in TypeScript

Collapse
 
gsarciotto profile image
Giovanni Sarciotto

Very interesting patterns!

Regarding the caveat, this happens because of duck-typing. I think one way you can solve it is using a typeguard with instanceof to assure that visitSquare receives an instance of Square and if not throw some error so you will hopefully see this problem whenever testing