DEV Community

Discussion on: TypeScript: type compatibility vs duck typing

Collapse
 
tqbit profile image
tq-bit

Well observed. You still need to put some elbow greese into properly distinguishing the two from one another.

I took your example and extended it a bit using polymorphism as I missed to show it in my sloppy example above. Now even though the two classes are compatible, you will still receive the proper price for each product.

Sandbox