Why does TypeScript let you assign a RobotDog to a variable typed as Dog? Go!

Estimated read time 1 min read

Post Contenthttps://www.youtube.com/shorts/HvKALwVC9JM

​ In this Developer Challenge, a RobotDog can be assigned to a variable typed as Dog, even though RobotDog doesn’t extend Dog. At first glance, this feels like a type system bug. But TypeScript is working as intended!
The twist? Add a private field to Dog and suddenly the assignment fails. Why does this happen, and what does it reveal about how TypeScript checks compatibility? Drop your explanation in the comments!

Subscribe to Google for Developers → https://goo.gle/developers

Speakers: Meg Bauman   Read More Google for Developers 

You May Also Like

More From Author