Typescript Classes 10 exercises

Ensure a Class Adheres to a Contract

Continuing with the Shape class. It has properties for #x and #y, a constructor, a position getter, and a move function.

We now also have an IShape type, which has a position property that includes x and y coordinates, as well as a move function that takes in a deltaX and `delta

Loading exercise


00:00 Okay, we're back with our class shape, which has X and Y, it has a constructor, which sets the initial X and Y, has a position getter, and it has a move function. And we have up here a type called IShape. And this type, IShape, has a position of X and Y and it has

00:16 a move function, which has delta X and delta Y. Your job here is to try to find a piece of syntax which lets us guarantee that class shape meets the contract described in type IShape, that it kind of implements this contract. And there is a special piece of syntax in

00:35 TypeScript that lets you do it. And I did just drop the I word just a little few seconds ago, which might give you a clue as to how you can get this done. Good luck.