javascript - ionic : Typescript Error

标签 javascript angularjs typescript cordova ionic-framework

我是 Ionic 新手,当我运行构建命令时遇到这个问题。 $ ionic cordova 构建 android

[00:34:40]  typescript: src/pages/becomevendor/becomevendor.ts, line: 97 
        Argument of type '(result: NativeGeocoderReverseResult) => void' is not assignable to parameter of type 
        '(value: NativeGeocoderReverseResult[]) => void | PromiseLike<void>'. Types of parameters 'result' and 
        'value' are incompatible. Type 'NativeGeocoderReverseResult[]' is not assignable to type 
        'NativeGeocoderReverseResult'. Property 'countryCode' is missing in type 'NativeGeocoderReverseResult[]'. 

  L96:  this.nativeGeocoder.reverseGeocode(this.becomeVendorDetails.latitude, this.becomeVendorDetails.longitude)
  L97:      .then((result: NativeGeocoderReverseResult) => {
  L98:          let addressLocal: any = JSON.stringify(result[0]);

        Argument of type '(result: NativeGeocoderReverseResult) => void' is not assignable to parameter of type 
[00:34:40]  typescript: src/pages/postjob/postjob.ts, line: 176 
        '(value: NativeGeocoderReverseResult[]) => void | PromiseLike<void>'. Types of parameters 'result' and 
        'value' are incompatible. Type 'NativeGeocoderReverseResult[]' is not assignable to type 
        'NativeGeocoderReverseResult'. 

 L175:  this.nativeGeocoder.reverseGeocode(this.bookingdetail.latitude, this.bookingdetail.longitude)
 L176:      .then((result: NativeGeocoderReverseResult) => {
 L177:          let addressLocal: any = JSON.stringify(result[0]);

        Argument of type '(result: NativeGeocoderReverseResult) => void' is not assignable to parameter of type 
        '(value: NativeGeocoderReverseResult[]) => void | PromiseLike<void>'. Types of parameters 'result' and 
[00:34:40]  typescript: src/pages/vendoreditprofile/vendoreditprofile.ts, line: 356 
        'value' are incompatible. Type 'NativeGeocoderReverseResult[]' is not assignable to type 
        'NativeGeocoderReverseResult'. 

 L355:  this.nativeGeocoder.reverseGeocode(this.profileDetail.latitude, this.profileDetail.longitude)
 L356:      .then((result: NativeGeocoderReverseResult) => {
 L357:          let addressLocal: any = JSON.stringify(result[0]);

在源代码中,becomevendor.ts

displayAddress() {
    this.nativeGeocoder.reverseGeocode(this.becomeVendorDetails.latitude, this.becomeVendorDetails.longitude)
        .then((result: NativeGeocoderReverseResult) => {
            let addressLocal: any = JSON.stringify(result[0]);
            let addressLoc = JSON.parse(addressLocal);
            let addressData = addressLoc.thoroughfare + ',' + addressLoc.locality + ',' + addressLoc.postalCode;
            this.becomeVendorForm.controls['address'].setValue(addressData);
            this.autocomplete.query = addressData;
        })
        .catch((error: any) => console.log(error));
}
close() {
    this.viewCtrl.dismiss();
}

此保存功能在其他 2 个文件中也可用。

最佳答案

看起来是因为 nativeGeocoder.reverseGeocode 返回 NativeGeocoderReverseResult 的列表

更改结果来自:

    .then((result: NativeGeocoderReverseResult) => {

    .then((result: NativeGeocoderReverseResult[]) => {

关于javascript - ionic : Typescript Error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51901573/

相关文章:

javascript - 是闭合路径内的点 - SVG Javascript

angularjs - ng-repeat 似乎不起作用

javascript - 如何通过母 div 的 id 更改所有内部 div 的光标样式

用于循环 HTMLCollection 的 typescript

typescript - 向剩余运算符添加输入

javascript - 如何在使用 jQuery 追加之前克隆、修改(增加一些元素)?

javascript - HTML/CSS/JS - 自适应网格布局?

javascript - typescript 中的 String[] 和 [String] 有什么区别?

php - 在 PHP 中,如何打印带 2 位小数的数字,但前提是已经有小数?

angularjs - 如何在 angular-ui $modal *before* 模态关闭之前执行回调?