我有以下课程:
export class CellLayer extends BaseLayer { constructor(name: string,type: LayerType,private mapService: MapService) { super(name,type,mapService); } }
和相应的抽象类:
export abstract class BaseLayer implements ILayer { private _name: string; private _type: LayerType; constructor(name: string,private mapService: MapService) { this._name = name; this._type = type; } }
应将全局MapService对象传递给这两个类.
但是,我现在收到以下错误:
Types have separate declarations of a private property ‘mapService’.
(6,14): Class ‘CellLayer’ incorrectly extends base class ‘BaseLayer’.
解决方法
保护它.
Private表示属性对当前类是私有的,因此子组件不能覆盖它,也不能定义它.
export abstract class BaseLayer implements ILayer { private _name: string; private _type: LayerType; constructor(name: string,protected mapService: MapService) { this._name = name; this._type = type; } } export class CellLayer extends BaseLayer { constructor(name: string,protected mapService: MapService) { super(name,mapService); } }