Solución
solution.tsTypeScript
export function createAnimal(name: string, sound: string): string {
// Define un objeto base con el método speak usando template literal
// Usa Object.create() para crear el animal con ese prototype
// Asigna name y sound como propiedades propias
// Retorna el resultado de llamar a speak()
interface Animals {
nombre: string;
sonido: string;
speak: () => string;
}
const animalBase: Partial<Animals> = {
speak(): string {
return `${this.nombre} dice: ${this.sonido}`
}
}
const animal: Animals = Object.create(animalBase);
animal.nombre = name;
animal.sonido = sound;
return animal.speak();
}
0respuestas