In TypeScript, I have been always doing something like
interface People {
name: string;
}
class Employee implements People {
name: string;
foo: string;
}
when I implement interfaces through classes.
However, I alway wonder why should I have to redeclare the attributes.
I bought a book about Angular and Design Patterns and read that if you do
interface People {
name: string;
}
class Employee implements People {
foo: string;
}
in TypeScript, that should inherit the properties from the interfaces, so I was surprised.
Then, I have tried but nothing the compiler fails, so is that correct? Should I change something in my tsconfig or whatever like that?
I am curious about this question and I couldn't find a clear answer on GitHub about that, so I would like to not duplicate code or have more boilerplate, if it is possible.
Aucun commentaire:
Enregistrer un commentaire