TypeScript-联合类型-命名约定

时间:2018-10-12 10:03:40

标签: typescript naming-conventions union-types

我是TS的新手,有一些问题需要解决。 我有这个界面:

interface ILayerSet {
  addLayer(layer: ILayer): void;
  removeLayer(layer: ILayer): void;
  removeLayer(position: number): void;
  removeLayer(func: (layer: ILayer) => boolean): void;
}

我已经阅读了有关联合类型并重写的内容。然后我开始怀疑论据的名称。它可以是ILayer,数字和函数,那么如何更正此参数的名称?

interface ILayerSet {
  addLayer(layer: ILayer): void;
  removeLayer(WHATNAME: ILayer | number | ((layer: ILayer) => boolean)): void;
}

也许更好的解决方案是这样的?

interface ILayerSet {
  addLayer(layer: ILayer): void;
  removeLayer(layer: ILayer): void;
  removeLayerByPosition(position: number): void;
  removeLayerByFunc(func: (layer: ILayer) => boolean): void;
}

您怎么看?

0 个答案:

没有答案