Why am I encountering an error under the 'name' interface with an excess property when using an object literal? There is no error in the case of a class, why is this happening?
export interface Analyzer {
run(matches: MatchData[]): string;
}
const literalObject: Analyzer = {
run(mtatches: MatchData[]): string {
return '';
},
name: 'asd', //error
}
export class WinsAnalysis implements Analyzer {
name: string = 'asd'; //fine
constructor(public team: string) {
}
run(matches: MatchData[]): string {
let wins = 0;
for (let match of matches) {
if (match[1] === this.team && match[5] === MatchResult.HomeWin) {
wins++;
} else if (match[2] === this.team && match[5] === MatchResult.AwayWin) {
wins++;
}
}
return `${this.team} won ${wins} times`;
}
}