2015-10-01 13 views
5

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; 
    } 
} 

risposta

3

Date un'occhiata a questo github issue. Sembra che il comportamento sia cambiato in 1.6. La mia ipotesi è che il corso che stai prendendo è stato scritto prima 1.6.

+0

gr8 lavorato. Thnx per il collegamento. –

Problemi correlati