01 / 05
Declare "I meet this shape"
The interface you wrote in chapter 2 put a name on a shape. Write implements after a class name and it becomes a declaration that "this class meets that shape".
Inside an interface, a method is written as just a name and a shape, like speak(): string;. No body. Writing the body is the class's job.
After that you declare class Dog implements Animal and put everything you promised into the class.
interface Animal { speak(): string;}class Dog implements Animal { speak(): string { return "woof"; }}console.log(new Dog().speak());Result
woof