美文网首页
typescript中构造函数类型引用

typescript中构造函数类型引用

作者: NanaCti | 来源:发表于2021-02-24 15:57 被阅读0次

    报错内容

    This expression is not constructable.
    Type 'Point' has no construct signatures.

    构造函数的类型无法直接引用

    class Point {
      constructor(lng: number, lat: number);
      lng: number;
      lat: number;
      equals(other: Point): boolean;
    }
    
    // 错误写法
    declare interface BMapGL {
      Point: Point ;
    }
    
    // 正确写法
    declare interface BMapGL {
      Point: { new (lng: number, lat: number): Point }; 
    }
    

    相关文章

      网友评论

          本文标题:typescript中构造函数类型引用

          本文链接:https://www.haomeiwen.com/subject/smusfltx.html