如何讓我的打字稿編譯器很快樂,而不必更改我在函數測試中收到的接口和typeof參數。打字稿鑄造
錯誤功能測試: -
"Property 'method2' does not exist on type 'xyz'. Did you mean 'method1'?"
interface xyz {
method1(): string;
}
class abc implements xyz {
method1() {
return "abc";
}
method2() {
return "new method";
}
}
function test(arg: xyz) {
alert(arg.method2());
}
你能解釋一下編譯器是什麼不開心的呢? – evolutionxbox
唯一的選擇是添加'method2'作爲界面的一部分 –
你的問題是什麼?什麼是編譯器錯誤?你想達到什麼目的? – k0pernikus