【发布时间】:2021-06-20 15:49:48
【问题描述】:
我正在尝试创建访问者设计模式,但我遇到了一个编译错误,尽管我尝试找到解决方案的时间很长,但我无法解决...
访客界面:
export interface Visitor {
visit(a: A): X;
visit(b: B): Y;
}
访客实现:
export class VisitorImp implements Visitor {
visit(a: A): X {
return a.getX();
}
visit(b: B): Y{
return b.getY();
}
}
这样,我有以下编译错误:
Property 'visit' in type 'VisitorImp' is not assignable to the same property in base type 'Visitor'.
Type '(a: A) => X' is not assignable to type '{ (a: A): X; (b: B): Y; }'.
Type 'X' is missing the following properties from type Y
我真的希望有人可以帮助我,因为它现在让我发疯!
【问题讨论】:
标签: typescript interface overloading visitor-pattern