這是我的問題: 我有一個類實現接口。方法問候應該有返回類型void
,但在我實現的類中它有string
和編譯器不警告我。和IDE都沒有(我使用PhpStorm)。 我錯過了什麼,或者這是故意的嗎?Typescript編譯器不檢查方法返回類型的有效性
interface Person {
sex: string;
greet() : void;
}
class Boy implements Person {
sex: 'M';
greet() {
return this.sex;
}
}
我使用打字稿2.0.10
[TypeScript playground](http://www.typescriptlang.org/play/index.html)也不會做出警告或錯誤。但是,如果你把'void'改成'number'(說'greet'不正確,因爲它返回一個字符串),它*會抱怨它。所以它與'void'有關。 –