如何让我的打字稿编译器很快乐,而不必更改我在函数测试中收到的接口和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