我从正在使用的库中收到以下界面:
export interface LatLng {
constructor(lat: number, lng: number): void;
lat(): number;
lng(): number;
}
如何创建此类的实现?(我需要一个测试模拟)一个外观自然的实现,其构造函数定义如下:
export class LatLngImpl implements LatLng {
constructor(private _lat: number, private _lng: number) { }
不编译:
Class 'LatLngImpl' incorrectly implements interface 'LatLng'. Types of property 'constructor' are incompatible. Type 'Function' is not assignable to type '(lat: number, lng: number) => >void'. Type 'Function' provides no match for the signature '(lat: number, lng: >number): void'
我在typescript中读到了constructor接口,但我认为它在这里不适用.
Edit:
我不理解的是界面中的constructor()
条声明.具有构造函数签名的接口使用new ()
语法.