Sto seguendo un corso di Pluralsight su TypeScript e questo genera un errore, mentre è spiegato che è un codice valido nel corso.Oggetto TypeScript che implementa l'interfaccia con l'errore di proprietà aggiuntive
errore TS2322: digitare '{favouriteSport: string; nome: stringa; bambini: numero; età: numero; calcPets:() => numero; makeYo ... 'non è assegnabile al tipo' Persona '. Il valore letterale dell'oggetto può specificare solo le proprietà note e "favouriteSport" non esiste nel tipo "Persona".
interface Person{
age: number,
name: string,
kids: number,
calcPets:()=> number;
makeYounger: (years: number) => void;
greet: (msg: string) => string;
}
var p: Person = {
favouriteSport: "tennis",
name: "Michael",
kids: 4,
age: 44,
calcPets: function(){
return this.kids * 2;
},
makeYounger: function(years: number){
this.age -= years;
},
greet: function(msg: string){
return msg + ', ' + this.name;
}
}
gr8 lavorato. Thnx per il collegamento. –