TS2420

Class 'Dog' incorrectly implements interface 'Animal'. Property 'name' is private in type 'Dog' but not in type 'Animal'.

Broken Code ❌

interface Animal {
  name: string;
}
 
class Dog implements Animal {
  constructor(private name: string = 'Bobby') {}
}

Fixed Code ✔️

The Animal interface defines a public name member. The name property in our Dog class must therefore also be public:

interface Animal {
  name: string;
}
 
class Dog implements Animal {
  constructor(public name: string = 'Bobby') {}
}

Video Tutorial