请问Typescript如何对原有类型进行扩展方法呢?

之前有个项目用js写的
有很多工具类啥的
想转到ts中来
虽然可以直接用
但是没有代码提示很伤嘛
于是就准备把以前的框架全部改写为ts版本
问题就来了

以前在js里对cc.Node 扩展过一些方法和成员
现在改成ts文件后编译就报错了
不知道怎么破

代码如下

/**

  • 扩展cc.Node.事件Type
  • @type {string}
    */
    cc.Node.EventType.TOGGLE = “toggle”;
    cc.Node.EventType.CLICK = “click”;

/**

  • 扩展cc.Node类
  • 新增 getChildComponent 方法来获得子物体身上的组件
  • @param ChildRelativePath 相对本节点的路径
  • @param ComponentType 查找类型
  • @returns {*}
    */
    cc.Node.prototype.getChildComponent = function(ChildRelativePath , ComponentType) {
    var Child = this.getChildByRelativePath(ChildRelativePath);
    if(Child)
    {
    var Comp = Child.getComponent(ComponentType);
    return Comp;
    }else{
    return null;
    }
    }

/**

  • 扩展cc.Node类

  • 新增 getChildByRelativePath 方法

  • 可通过相对路径来获得相对于本节点的子节点

  • @param ChildPath
    */
    cc.Node.prototype.getChildByRelativePath = function(ChildPath){
    var ChildNames = ChildPath.split("/");
    var Child = this;
    var index = 0;
    while(index < ChildNames.length)
    {
    Child = Child.getChildByName(ChildNames[index++]);
    }

    return Child;
    }

老哥,解决没有. 我也想知道

可以先在图片 里面,例如图片 ,然后在其他地方写上图片 。可以试试!