Skip to content

Instantly share code, notes, and snippets.

@tecnocrata
Created July 7, 2019 15:47
Show Gist options
  • Select an option

  • Save tecnocrata/d34cacee27cb4295f78ed47e251a9239 to your computer and use it in GitHub Desktop.

Select an option

Save tecnocrata/d34cacee27cb4295f78ed47e251a9239 to your computer and use it in GitHub Desktop.
Typescript entendiendo Shapes
//Shapes no esta directamente relacionado a la herencia
interface Mamifero{
cantidad:number
}
interface Comedor{
comida:string,
comer():number
}
class Animal implements Mamifero, Comedor{
comer(): number {
thrownewError("Method not implemented.");
}
cantidad: number;
comida: string;
}
class Perro {
cantidad:number
comida: string;
// comer(): number {
// throw new Error("Method not implemented.");
// }
}
let x = new Animal();
let y = new Perro();
x =y; //Error si NO descomentan el metodo comer, es decir si la clase perro no implementa comer
y = x;//Esta asignacion es posible incluso aunque ambos objetos sean instanciados de clases diferentes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment