Typescript中的不明确调用表达式

Typescript中的不明确调用表达式,typescript,Typescript,以下代码段创建了不明确的调用表达式错误: /// <reference path="typings/google.maps.d.ts" /> class GoogleMap { private geocoder; private latlng; constructor() { this.geocoder = new google.maps.Geocoder(); this.latlng = new google.maps.La

以下代码段创建了不明确的调用表达式错误:

/// <reference path="typings/google.maps.d.ts" />
class GoogleMap {
    private geocoder;
    private latlng;

    constructor() {
        this.geocoder = new google.maps.Geocoder();
        this.latlng = new google.maps.LatLng(51.165691, 10.451526000000058);
    }
    private setElements(): void {
        this.geocoder.geocode({ 'address': "Berlin", 'latLng': this.latlng }, (results) => {
            var infowindow = new google.maps.InfoWindow();
            infowindow.setContent(results[0].formatted_address); // 'Ambiguous call expression - could not choose overload'
        })
    }
还有一个奇怪的地方:当我将
infoWindow
声明为类变量时,我认为这种解决方法不是必需的


对我来说,这看起来像是一个bug,还是我遗漏了什么?

我可以看到,在API的d.ts文件中,geocode的回调函数参数似乎缺少类型定义,如果是这种情况,TypeScript默认将其类型定义为“any”,该对象内部的任何内容也定义为“any”类型

所以当你打电话的时候

infowindow.setContent(results[0].formatted_address);
TypeScript正在查找具有下一个签名的函数:

setContent(param1: any);

它没有在您的d.ts文件中定义,并且类型“any”可以是任何类型,这可能就是您出现此错误的原因。

这是不够的信息。发布你的
InfoWindow
类代码这个类属于Google Maps Api:你从哪里得到
.d.ts
或者某个地方有一个原生的TypeScript类?我使用的是Google.Maps.d.ts,我很确定我是通过NuGet包含它的。您认为此文件有问题吗?请将
infowindow.setContent
的声明添加到您的问题中,以便我们可以尝试一下?
setContent(param1: any);